db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r709900 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/services/io/CompressedNumber.java testing/org/apache/derbyTesting/unitTests/junit/CompressedNumberTest.java
Date Sun, 02 Nov 2008 18:14:57 GMT
Author: kahatlen
Date: Sun Nov  2 10:14:56 2008
New Revision: 709900

URL: http://svn.apache.org/viewvc?rev=709900&view=rev
Log:
DERBY-3770: Create a utility class for skipping data in an InputStream

Removed these unused methods from CompressedNumber:

  - readIntAndReturnIntPlusOverhead(byte[], int)
  - skipInt(DataInput)
  - skipInt(InputStream)
  - skipLong(DataInput)
  - skipLong(InputStream)

The skip methods were buggy because they didn't check the return value
from InputStream.skip() or DataInput.skipBytes() and could possibly
skip too few bytes.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/CompressedNumber.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/junit/CompressedNumberTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/CompressedNumber.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/CompressedNumber.java?rev=709900&r1=709899&r2=709900&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/CompressedNumber.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/CompressedNumber.java
Sun Nov  2 10:14:56 2008
@@ -257,137 +257,11 @@
         }
 	}
 
-    /**
-     * Return the compressed Int value + stored size of the length + 1
-     * <p>
-     * Given offset in array to beginning of compressed int, return the 
-     * value of the compressed int + the number of bytes used to store the
-     * length.
-     * <p>
-     * So 1 byte lengths will return: length + 1 + 1
-     * So 2 byte lengths will return: length + 2 + 1
-     * So 4 byte lengths will return: length + 4 + 1
-     * <p>
-     * Note that this routine will not work for lengths MAX_INT - (MAX_INT - 5).
-     * <p>
-     * This routine is currently used by the StorePage code to skip fields
-     * as efficiently as possible.  Since the page size is less than 
-     * (MAX_INT - 5) it is all right to use this routine.
-     *
-	 * @return compressed int value + length used to store the length.
-     *
-     * @param data   byte array containing the field.
-     * @param offset offset to beginning of field, ie. data[offset] contains
-     *               1st byte of the compressed int.
-     **/
-	public static final int readIntAndReturnIntPlusOverhead(
-    byte[]  data,
-    int     offset)
-    {
-        int value = data[offset];
-
-        if ((value & ~0x3f) == 0)
-        {
-            // length is stored in this byte, we also know that the 0x80 bit
-            // was not set, so no need to mask off the sign extension from
-            // the byte to int conversion.
-
-            // account for 1 byte stored length of field + 1 for all returns
-            return(value + 2);
-        }
-		else if ((value & 0x80) == 0)
-		{
-            // length is stored in 2 bytes.  only use low 6 bits from 1st byte.
-
-            if (SanityManager.DEBUG)
-            {
-                SanityManager.ASSERT((value & 0x40) == 0x40);
-            }
-
-            // top 8 bits of 2 byte length is stored in this byte, we also 
-            // know that the 0x80 bit was not set, so no need to mask off the 
-            // sign extension from the 1st byte to int conversion.  Need to
-            // mask the byte in data[offset + 1] to account for possible sign
-            // extension.
-
-            // add 3 to account for 2 byte length + 1 added to all returns
-
-            return((((value & 0x3f) << 8) | (data[offset + 1] & 0xff)) + 3);
-		}
-        else
-        {
-            // length is stored in 4 bytes.  only use low 7 bits from 1st byte.
-
-            if (SanityManager.DEBUG)
-            {
-                SanityManager.ASSERT((value & 0x80) == 0x80);
-            }
-
-            // top 8 bits of 4 byte length is stored in this byte, we also 
-            // know that the 0x80 bit was set, so need to mask off the 
-            // sign extension from the 1st byte to int conversion.  Need to
-            // mask the bytes from the next 3 bytes data[offset + 1,2,3] to 
-            // account for possible sign extension.
-
-
-            // add 5 to account for 4 byte length + 1 added to all returns
-            return(
-                (((value            & 0x7f) << 24) |
-                 ((data[offset + 1] & 0xff) << 16) |
-                 ((data[offset + 2] & 0xff) <<  8) |
-                  (data[offset + 3] & 0xff)) + 5);
-        }
-	}
-
-
-	/**
-		Skip an integer previously written by writeInt().
-
-		@exception IOException an exception was thrown by a method on in.
-	*/
-	public static final int skipInt(DataInput in) throws IOException {
-
-		int value = in.readUnsignedByte();
-
-		if ((value & 0x80) == 0x80) {
-			in.skipBytes(3);
-			return 4;
-		}
-
-		if ((value & 0x40) == 0x40) {
-			in.skipBytes(1);
-			return 2;
-		}
-
-		return 1;
-	}
-
 	/**
 		Skip an integer previously written by writeInt().
 
 		@exception IOException an exception was thrown by a method on in.
 	*/
-	public static final int skipInt(InputStream in) throws IOException {
-
-		int value = InputStreamUtil.readUnsignedByte(in);
-
-		int skipBytes = 0;
-
-		if ((value & 0x80) == 0x80) {
-			skipBytes = 3;
-		}
-		else if ((value & 0x40) == 0x40) {
-			skipBytes = 1;
-		}
-
-		if (skipBytes != 0) {
-			if (in.skip(skipBytes) != skipBytes)
-				throw new EOFException();
-		}
-
-
-		return skipBytes + 1;
-	}
 
 	/**
 		Return the number of bytes that would be written by a writeInt call
@@ -608,59 +482,6 @@
 		}
 	}
 
-	/**
-		Skip a long previously written by writeLong().
-
-		@exception IOException an exception was thrown by a method on in.
-	*/
-	public static final int skipLong(DataInput in) throws IOException {
-
-		long value = in.readUnsignedByte();
-
-		if ((value & 0x80) == 0x80)
-		{
-			in.skipBytes(7);
-			return 8;
-		}
-		
-		
-		if ((value & 0x40) == 0x40)
-		{
-			in.skipBytes(3);
-			return 4;
-
-		}
-
-		in.skipBytes(1);
-		return 2;
-	}
-
-	/**
-		Skip a long previously written by writeLong().
-
-		@exception IOException an exception was thrown by a method on in.
-	*/
-	public static final int skipLong(InputStream in) throws IOException {
-
-		int value = InputStreamUtil.readUnsignedByte(in);
-
-		int skipBytes;
-
-		if ((value & 0x80) == 0x80) {
-			skipBytes = 7;
-		}
-		else if ((value & 0x40) == 0x40) {
-			skipBytes = 3;
-		}
-		else
-			skipBytes = 1;
-
-		if (in.skip(skipBytes) != skipBytes)
-			throw new EOFException();
-
-		return skipBytes + 1;
-	}
-
 	public static final int sizeLong(long value) {
 
 		if (value <= 0x3fff) {

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/junit/CompressedNumberTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/junit/CompressedNumberTest.java?rev=709900&r1=709899&r2=709900&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/junit/CompressedNumberTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/junit/CompressedNumberTest.java
Sun Nov  2 10:14:56 2008
@@ -189,16 +189,6 @@
 
         assertEquals("MISMATCH frome readInt(byte[], offset)", i,
                      CompressedNumber.readInt(holder, 0));
-
-        ais.setPosition(0);
-        assertEquals("MISMATCH skip length", length,
-                     CompressedNumber.skipInt(in));
-
-        assertEquals("MISMATCH readIntAndReturnIntPlusOverhead() return",
-                     length + i + 1,
-                CompressedNumber.readIntAndReturnIntPlusOverhead(holder, 0));
-
-        assertEquals("MISMATCH skip position", length, ais.getPosition());
     }
 
 
@@ -235,11 +225,5 @@
         ais.setPosition(0);
         assertEquals("MISMATCH value in readLong(DataInput)", l,
                      CompressedNumber.readLong(in));
-
-        ais.setPosition(0);
-        assertEquals("MISMATCH skip length", length,
-                     CompressedNumber.skipLong(in));
-
-        assertEquals("MISMATCH skip position", length, ais.getPosition());
     }
 }



Mime
View raw message