db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r547653 - /db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/UTF8Reader.java
Date Fri, 15 Jun 2007 12:35:55 GMT
Author: kristwaa
Date: Fri Jun 15 05:35:54 2007
New Revision: 547653

URL: http://svn.apache.org/viewvc?view=rev&rev=547653
Log:
DERBY-2824: Improve error reporting, fix whitespace/formatting issues and replace tabs in
UTF8Reader. Replaces the tabs with spaces.
Patch file: derby-2824-1a-tabs_to_spaces.diff

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/UTF8Reader.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/UTF8Reader.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/UTF8Reader.java?view=diff&rev=547653&r1=547652&r2=547653
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/UTF8Reader.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/UTF8Reader.java Fri Jun 15
05:35:54 2007
@@ -38,36 +38,36 @@
 public final class UTF8Reader extends Reader
 {
 
-	private InputStream in;
+    private InputStream in;
     /** Stream store that can reposition itself on request. */
     private final PositionedStoreStream positionedIn;
     /** Store last visited position in the store stream. */
     private long rawStreamPos = 0L;
-	private final long         utfLen;	// bytes
-	private long        utfCount;		// bytes
-	private long		readerCharCount; // characters
-	private long		maxFieldSize;	// characeters
-
-	private char[]		buffer = new char[8 * 1024];
-	private int			charactersInBuffer;	// within buffer
-	private int			readPositionInBuffer;
+    private final long         utfLen;    // bytes
+    private long        utfCount;        // bytes
+    private long        readerCharCount; // characters
+    private long        maxFieldSize;    // characeters
+
+    private char[]        buffer = new char[8 * 1024];
+    private int            charactersInBuffer;    // within buffer
+    private int            readPositionInBuffer;
 
-	private boolean		noMoreReads;
+    private boolean        noMoreReads;
 
     // maintain a reference to the parent object so that it can't get 
     // garbage collected until we are done with the stream.
     private ConnectionChild      parent;
 
-	public UTF8Reader(
+    public UTF8Reader(
     InputStream in,
-	long maxFieldSize,
+    long maxFieldSize,
     ConnectionChild      parent,
-	Object synchronization) 
+    Object synchronization) 
         throws IOException, SQLException
-	{
-		super(synchronization);
-		this.maxFieldSize = maxFieldSize;
-		this.parent = parent;
+    {
+        super(synchronization);
+        this.maxFieldSize = maxFieldSize;
+        this.parent = parent;
 
         parent.setupContextStack();
         try {
@@ -103,7 +103,7 @@
         } finally {
             parent.restoreContextStack();
         }
-	}
+    }
 
     /**
      * Constructs a <code>UTF8Reader</code> using a stream.
@@ -140,193 +140,193 @@
         this.in = new BufferedInputStream(in);
     }
 
-	/*
-	** Reader implemention.
-	*/
-	public int read() throws IOException
-	{
-		synchronized (lock) {
-
-			// check if closed..
-			if (noMoreReads)
-				throw new IOException();
-
-			if (readPositionInBuffer >= charactersInBuffer) {
-				if (fillBuffer()) {
-					return -1;
-				}
-				readPositionInBuffer = 0;
-			}
-
-			return buffer[readPositionInBuffer++];
-		}
-	}
-
-	public int read(char[] cbuf, int off, int len) throws IOException
-	{
-		synchronized (lock) {
-			// check if closed..
-			if (noMoreReads)
-				throw new IOException();
-
-			if (readPositionInBuffer >= charactersInBuffer) {
-				if (fillBuffer()) {
-					return -1;
-				}
-				readPositionInBuffer = 0;
-			}
-
-			int remainingInBuffer = charactersInBuffer - readPositionInBuffer;
-
-			if (len > remainingInBuffer)
-				len = remainingInBuffer;
-
-			System.arraycopy(buffer, readPositionInBuffer, cbuf, off, len);
-			readPositionInBuffer += len;
-
-			return len;
-		}
-	}
-
-	public long skip(long len) throws IOException {
-		if (len < 0) {
-			throw new IllegalArgumentException(
-				"Number of characters to skip must be positive:" + len);
-		}
-		synchronized (lock) {
-			// check if closed..
-			if (noMoreReads)
-				throw new IOException();
-
-			if (readPositionInBuffer >= charactersInBuffer) {
-				// do somthing
-				if (fillBuffer()) {
-					return 0L;
-				}
-				readPositionInBuffer = 0;
-			}
-
-			int remainingInBuffer = charactersInBuffer - readPositionInBuffer;
-
-			if (len > remainingInBuffer)
-				len = remainingInBuffer;
-
-			readPositionInBuffer += len;
-
-			return len;
-		}
-
-	}
-
-	public void close()
-	{
-		synchronized (lock) {
-			closeIn();
-			parent  = null;
-			noMoreReads = true;
-		}
-	}
-
-	/*
-	** Methods just for Derby's JDBC driver
-	*/
-
-	public int readInto(StringBuffer sb, int len) throws IOException {
-
-		synchronized (lock) {
-			if (readPositionInBuffer >= charactersInBuffer) {
-				if (fillBuffer()) {
-					return -1;
-				}
-				readPositionInBuffer = 0;
-			}
-
-			int remainingInBuffer = charactersInBuffer - readPositionInBuffer;
-
-			if (len > remainingInBuffer)
-				len = remainingInBuffer;
-			sb.append(buffer, readPositionInBuffer, len);
-
-			readPositionInBuffer += len;
-
-			return len;
-		}
-	}
-	int readAsciiInto(byte[] abuf, int off, int len) throws IOException {
-
-		synchronized (lock) {
-			if (readPositionInBuffer >= charactersInBuffer) {
-				if (fillBuffer()) {
-					return -1;
-				}
-				readPositionInBuffer = 0;
-			}
-
-			int remainingInBuffer = charactersInBuffer - readPositionInBuffer;
-
-			if (len > remainingInBuffer)
-				len = remainingInBuffer;
-
-			char[] lbuffer = buffer;
-			for (int i = 0; i < len; i++) {
-				char c = lbuffer[readPositionInBuffer + i];
-				byte cb;
-				if (c <= 255)
-					cb = (byte) c;
-				else
-					cb = (byte) '?'; // Question mark - out of range character.
-
-				abuf[off + i] = cb;
-			}
-
-			readPositionInBuffer += len;
-
-			return len;
-		}
-	}
-
-	/*
-	** internal implementation
-	*/
-
-
-	private void closeIn() {
-		if (in != null) {
-			try {
-				in.close();
-			} catch (IOException ioe) {
-			} finally {
-				in = null;
-			}
-		}
-	}
-	private IOException utfFormatException(String s) {
-		noMoreReads = true;
-		closeIn();
-		return new UTFDataFormatException(s);
-	}
-
-	private IOException utfFormatException() {
-		noMoreReads = true;
-		closeIn();
-		return new UTFDataFormatException();
-	}
-
-	/**
-		Fill the buffer, return true if eof has been reached.
-	*/
+    /*
+    ** Reader implemention.
+    */
+    public int read() throws IOException
+    {
+        synchronized (lock) {
+
+            // check if closed..
+            if (noMoreReads)
+                throw new IOException();
+
+            if (readPositionInBuffer >= charactersInBuffer) {
+                if (fillBuffer()) {
+                    return -1;
+                }
+                readPositionInBuffer = 0;
+            }
+
+            return buffer[readPositionInBuffer++];
+        }
+    }
+
+    public int read(char[] cbuf, int off, int len) throws IOException
+    {
+        synchronized (lock) {
+            // check if closed..
+            if (noMoreReads)
+                throw new IOException();
+
+            if (readPositionInBuffer >= charactersInBuffer) {
+                if (fillBuffer()) {
+                    return -1;
+                }
+                readPositionInBuffer = 0;
+            }
+
+            int remainingInBuffer = charactersInBuffer - readPositionInBuffer;
+
+            if (len > remainingInBuffer)
+                len = remainingInBuffer;
+
+            System.arraycopy(buffer, readPositionInBuffer, cbuf, off, len);
+            readPositionInBuffer += len;
+
+            return len;
+        }
+    }
+
+    public long skip(long len) throws IOException {
+        if (len < 0) {
+            throw new IllegalArgumentException(
+                "Number of characters to skip must be positive:" + len);
+        }
+        synchronized (lock) {
+            // check if closed..
+            if (noMoreReads)
+                throw new IOException();
+
+            if (readPositionInBuffer >= charactersInBuffer) {
+                // do somthing
+                if (fillBuffer()) {
+                    return 0L;
+                }
+                readPositionInBuffer = 0;
+            }
+
+            int remainingInBuffer = charactersInBuffer - readPositionInBuffer;
+
+            if (len > remainingInBuffer)
+                len = remainingInBuffer;
+
+            readPositionInBuffer += len;
+
+            return len;
+        }
+
+    }
+
+    public void close()
+    {
+        synchronized (lock) {
+            closeIn();
+            parent  = null;
+            noMoreReads = true;
+        }
+    }
+
+    /*
+    ** Methods just for Derby's JDBC driver
+    */
+
+    public int readInto(StringBuffer sb, int len) throws IOException {
+
+        synchronized (lock) {
+            if (readPositionInBuffer >= charactersInBuffer) {
+                if (fillBuffer()) {
+                    return -1;
+                }
+                readPositionInBuffer = 0;
+            }
+
+            int remainingInBuffer = charactersInBuffer - readPositionInBuffer;
+
+            if (len > remainingInBuffer)
+                len = remainingInBuffer;
+            sb.append(buffer, readPositionInBuffer, len);
+
+            readPositionInBuffer += len;
+
+            return len;
+        }
+    }
+    int readAsciiInto(byte[] abuf, int off, int len) throws IOException {
+
+        synchronized (lock) {
+            if (readPositionInBuffer >= charactersInBuffer) {
+                if (fillBuffer()) {
+                    return -1;
+                }
+                readPositionInBuffer = 0;
+            }
+
+            int remainingInBuffer = charactersInBuffer - readPositionInBuffer;
+
+            if (len > remainingInBuffer)
+                len = remainingInBuffer;
+
+            char[] lbuffer = buffer;
+            for (int i = 0; i < len; i++) {
+                char c = lbuffer[readPositionInBuffer + i];
+                byte cb;
+                if (c <= 255)
+                    cb = (byte) c;
+                else
+                    cb = (byte) '?'; // Question mark - out of range character.
+
+                abuf[off + i] = cb;
+            }
+
+            readPositionInBuffer += len;
+
+            return len;
+        }
+    }
+
+    /*
+    ** internal implementation
+    */
+
+
+    private void closeIn() {
+        if (in != null) {
+            try {
+                in.close();
+            } catch (IOException ioe) {
+            } finally {
+                in = null;
+            }
+        }
+    }
+    private IOException utfFormatException(String s) {
+        noMoreReads = true;
+        closeIn();
+        return new UTFDataFormatException(s);
+    }
+
+    private IOException utfFormatException() {
+        noMoreReads = true;
+        closeIn();
+        return new UTFDataFormatException();
+    }
+
+    /**
+        Fill the buffer, return true if eof has been reached.
+    */
     //@GuardedBy("lock")
-	private boolean fillBuffer() throws IOException
-	{
-		if (in == null)
-			return true;
-
-		charactersInBuffer = 0;
-
-		try {
-		try {
-		
-			parent.setupContextStack();
+    private boolean fillBuffer() throws IOException
+    {
+        if (in == null)
+            return true;
+
+        charactersInBuffer = 0;
+
+        try {
+        try {
+        
+            parent.setupContextStack();
             // If we are operating on a positioned stream, reposition it to
             // continue reading at the position we stopped last time.
             if (this.positionedIn != null) {
@@ -337,83 +337,83 @@
                 }
             }
 readChars:
-		while (
-				(charactersInBuffer < buffer.length) &&
-			    ((utfCount < utfLen) || (utfLen == 0)) &&
-				((maxFieldSize == 0) || (readerCharCount < maxFieldSize))
-			  )
-		{
-			int c = in.read();
-			if (c == -1) {
-				if (utfLen == 0) {
-					closeIn();
-					break readChars;
-				}
-				throw utfFormatException();
-			}
-
-			int finalChar;
-			switch (c >> 4) { 
-				case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
-					// 0xxxxxxx
-					utfCount++;
-					finalChar = c;
-					break;
-
-				case 12: case 13:
-					{
-					// 110x xxxx   10xx xxxx
-					utfCount += 2;
-					int char2 = in.read();
-					if (char2 == -1)
-						throw utfFormatException();
-
-					if ((char2 & 0xC0) != 0x80)
-						throw utfFormatException();		  
-					finalChar = (((c & 0x1F) << 6) | (char2 & 0x3F));
-					break;
-					}
-
-				case 14:
-					{
-					// 1110 xxxx  10xx xxxx  10xx xxxx
-					utfCount += 3;
-					int char2 = in.read();
-					int char3 = in.read();
-					if (char2 == -1 || char3 == -1)
-						throw utfFormatException();
-
-					if ((c == 0xE0) && (char2 == 0) && (char3 == 0))
-					{
-						if (utfLen == 0) {
-							// we reached the end of a long string,
-							// that was terminated with
-							// (11100000, 00000000, 00000000)
-							closeIn();
-							break readChars;
-						}
-						throw utfFormatException();
-					}
-
-					if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
-						throw utfFormatException();	
-
-					finalChar = (((c & 0x0F) << 12) |
-							   ((char2 & 0x3F) << 6) |
-							   ((char3 & 0x3F) << 0));
-					}
-					break;
-
-				default:
-					// 10xx xxxx,  1111 xxxx
-					throw utfFormatException();		  
-			}
-
-			buffer[charactersInBuffer++] = (char) finalChar;
-			readerCharCount++;
-		}
-		if (utfLen != 0 && utfCount > utfLen) 
-			throw utfFormatException("utfCount " + utfCount + " utfLen " + utfLen);		  
+        while (
+                (charactersInBuffer < buffer.length) &&
+                ((utfCount < utfLen) || (utfLen == 0)) &&
+                ((maxFieldSize == 0) || (readerCharCount < maxFieldSize))
+              )
+        {
+            int c = in.read();
+            if (c == -1) {
+                if (utfLen == 0) {
+                    closeIn();
+                    break readChars;
+                }
+                throw utfFormatException();
+            }
+
+            int finalChar;
+            switch (c >> 4) { 
+                case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
+                    // 0xxxxxxx
+                    utfCount++;
+                    finalChar = c;
+                    break;
+
+                case 12: case 13:
+                    {
+                    // 110x xxxx   10xx xxxx
+                    utfCount += 2;
+                    int char2 = in.read();
+                    if (char2 == -1)
+                        throw utfFormatException();
+
+                    if ((char2 & 0xC0) != 0x80)
+                        throw utfFormatException();          
+                    finalChar = (((c & 0x1F) << 6) | (char2 & 0x3F));
+                    break;
+                    }
+
+                case 14:
+                    {
+                    // 1110 xxxx  10xx xxxx  10xx xxxx
+                    utfCount += 3;
+                    int char2 = in.read();
+                    int char3 = in.read();
+                    if (char2 == -1 || char3 == -1)
+                        throw utfFormatException();
+
+                    if ((c == 0xE0) && (char2 == 0) && (char3 == 0))
+                    {
+                        if (utfLen == 0) {
+                            // we reached the end of a long string,
+                            // that was terminated with
+                            // (11100000, 00000000, 00000000)
+                            closeIn();
+                            break readChars;
+                        }
+                        throw utfFormatException();
+                    }
+
+                    if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
+                        throw utfFormatException();    
+
+                    finalChar = (((c & 0x0F) << 12) |
+                               ((char2 & 0x3F) << 6) |
+                               ((char3 & 0x3F) << 0));
+                    }
+                    break;
+
+                default:
+                    // 10xx xxxx,  1111 xxxx
+                    throw utfFormatException();          
+            }
+
+            buffer[charactersInBuffer++] = (char) finalChar;
+            readerCharCount++;
+        }
+        if (utfLen != 0 && utfCount > utfLen) 
+            throw utfFormatException("utfCount " + utfCount + " utfLen " + utfLen);     
    
 
         if (charactersInBuffer != 0) {
             if (this.positionedIn != null) {
@@ -421,30 +421,30 @@
                 // we let go the next time we fill the buffer.
                 this.rawStreamPos = this.positionedIn.getPosition();
             }
-			return false;
+            return false;
         }
 
-		closeIn();
-		return true;
-		} finally {
-			parent.restoreContextStack();
-		}
-		} catch (SQLException sqle) {
+        closeIn();
+        return true;
+        } finally {
+            parent.restoreContextStack();
+        }
+        } catch (SQLException sqle) {
             IOException ioe =
                 new IOException(sqle.getSQLState() + ": " + sqle.getMessage());
             ioe.initCause(sqle);
             throw ioe;
-		}
-	}
+        }
+    }
 
 
-	// this method came from java.io.DataInputStream
+    // this method came from java.io.DataInputStream
     private final int readUnsignedShort() throws IOException {
-		int ch1 = in.read();
-		int ch2 = in.read();
-		if ((ch1 | ch2) < 0)
-			throw new EOFException();
+        int ch1 = in.read();
+        int ch2 = in.read();
+        if ((ch1 | ch2) < 0)
+            throw new EOFException();
 
-		return (ch1 << 8) + (ch2 << 0);
-	}
+        return (ch1 << 8) + (ch2 << 0);
+    }
 }



Mime
View raw message