db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r522167 - in /db/derby/code/trunk/java/engine/org/apache/derby: iapi/services/io/ArrayInputStream.java impl/store/raw/data/FileContainer.java impl/store/raw/log/FileLogger.java impl/store/raw/log/FlushedScanHandle.java
Date Sun, 25 Mar 2007 06:08:56 GMT
Author: kahatlen
Date: Sat Mar 24 23:08:55 2007
New Revision: 522167

URL: http://svn.apache.org/viewvc?view=rev&rev=522167
Log:
DERBY-2118: Cleanup of ArrayInputStream

- Patch which improves the clearLimit() method by removing the
  possibility that the byte array is ever null.

- Instead of using null when creating an empty ArrayInputStream an
  empty array is used instead.

- Remove some unused methods.

- Change some callers of the 2-arg setLimit() to the 1-arg setLimit()
  as it is more efficient.

- Fix a bug where setData() would not reset the position to zero
  (previously it was unmodified at a potentially invalid position)

Contributed by Daniel John Debrunner.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/ArrayInputStream.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/FileContainer.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/FileLogger.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/FlushedScanHandle.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/ArrayInputStream.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/ArrayInputStream.java?view=diff&rev=522167&r1=522166&r2=522167
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/ArrayInputStream.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/ArrayInputStream.java
Sat Mar 24 23:08:55 2007
@@ -30,6 +30,7 @@
 
 import org.apache.derby.iapi.services.io.LimitObjectInput;
 import org.apache.derby.iapi.services.io.ErrorObjectInput;
+import org.apache.derby.iapi.util.ReuseFactory;
 
 import java.io.UTFDataFormatException;
 
@@ -46,38 +47,40 @@
 	private int		end;		// exclusive
 	private int		position;
 
+	/**
+	 * Create an ArrayInputStream with a zero length byte array.
+	 * The position is set to 0 and the limit is the entire byte array.
+	 *
+	 */
 	public ArrayInputStream() {
-		this(null);
+		this(ReuseFactory.getZeroLenByteArray());
 	}
 
 	private ErrorObjectInput oi;
 
+	/**
+	 * Create an ArrayInputStream with the passed in data.
+	 * The position is set to 0 and the limit is the entire byte array.
+	 * @param data
+	 */
 	public ArrayInputStream(byte[] data) {
 		super();
 		setData(data);
 		oi = new org.apache.derby.iapi.services.io.FormatIdInputStream(this);
 	}
 
-	public ArrayInputStream(byte[] data, int offset, int length) throws IOException {
-		this(data);
-		setLimit(offset, length);
-	}
-
 	/*
 	** Public methods
 	*/
 
 	/**
 		Set the array of bytes to be read.
+		Position is set to zero.
 	*/
 	public void setData(byte[] data) {
 		pageData = data;
-		clearLimit();
-	}
-
-	public void setData(byte[] data, int offset, int length) throws IOException {
-		pageData = data;
-		setLimit(offset, length);
+		start = position = 0;
+		end = data.length;
 	}
 
 	/**
@@ -203,16 +206,10 @@
 		@see Limit#clearLimit
 	*/
 	public final int clearLimit() {
-
-		if (pageData != null) {
-			start = 0;
-			int remainingBytes = end - position;
-			end = pageData.length;
-			return remainingBytes;
-		} else {
-			start = end = position = 0;
-			return 0;
-		}
+        start = 0;
+        int remainingBytes = end - position;
+        end = pageData.length;
+        return remainingBytes;
 	}
 
 	/*

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/FileContainer.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/FileContainer.java?view=diff&rev=522167&r1=522166&r2=522167
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/FileContainer.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/FileContainer.java
Sat Mar 24 23:08:55 2007
@@ -795,7 +795,7 @@
 	{
 		ArrayInputStream inStream = new ArrayInputStream(a);
 
-		inStream.setLimit(0, CONTAINER_INFO_SIZE);
+		inStream.setLimit(CONTAINER_INFO_SIZE);
 		int fid = inStream.readInt();
 		if (fid != formatIdInteger)
         {
@@ -1046,7 +1046,7 @@
 
 		try
 		{			
-			inStream.setLimit(0, CONTAINER_INFO_SIZE);
+			inStream.setLimit(CONTAINER_INFO_SIZE);
 
 			int fid = inStream.readInt();
 			if (fid != formatIdInteger)

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/FileLogger.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/FileLogger.java?view=diff&rev=522167&r1=522166&r2=522167
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/FileLogger.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/FileLogger.java Sat
Mar 24 23:08:55 2007
@@ -986,7 +986,7 @@
 				{
 					int optionalDataLength = rawInput.readInt();
 					int savePosition = rawInput.getPosition();
-					rawInput.setLimit(savePosition, optionalDataLength);
+					rawInput.setLimit(optionalDataLength);
 	
 					compensation = lop.generateUndo(t, rawInput);
 
@@ -1471,7 +1471,7 @@
                     }
 
 					int dataLength = logIn.readInt();
-					logIn.setLimit(logIn.getPosition(), dataLength);
+					logIn.setLimit(dataLength);
 										
 					// even though the log has already been written, we need to
 					// tie the page to the log stream so that if redo failed

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/FlushedScanHandle.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/FlushedScanHandle.java?view=diff&rev=522167&r1=522166&r2=522167
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/FlushedScanHandle.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/log/FlushedScanHandle.java
Sat Mar 24 23:08:55 2007
@@ -136,7 +136,7 @@
 		{
 			int dataLength = rawInput.readInt();
 			readOptionalData = true;
-			rawInput.setLimit(rawInput.getPosition(), dataLength);
+			rawInput.setLimit(dataLength);
 			return rawInput;
 		}
 



Mime
View raw message