diff --git a/.classpath b/.classpath
index 19e0e62..0136fe4 100644
--- a/.classpath
+++ b/.classpath
@@ -4,7 +4,9 @@
- * This method returns the result of {@link #in in}.available().
- *
- * @return an estimate of the number of bytes that can be read (or skipped
- * over) from this input stream without blocking.
- * @exception IOException if an I/O error occurs.
- */
- public int available() throws IOException {
- return in.available();
- }
-
-
-
- /**
- * Marks the current position in this input stream. A subsequent
- * call to the reset method repositions this stream at
- * the last marked position so that subsequent reads re-read the same bytes.
- *
- * The readlimit argument tells this input stream to
- * allow that many bytes to be read before the mark position gets
- * invalidated.
- *
- * This method simply performs in.mark(readlimit).
- *
- * @param readlimit the maximum limit of bytes that can be read before
- * the mark position becomes invalid.
- * @see java.io.FilterInputStream#in
- * @see java.io.FilterInputStream#reset()
- */
- public synchronized void mark(int readlimit) {
- in.mark(readlimit);
- }
-
- /**
- * Repositions this stream to the position at the time the
- * mark method was last called on this input stream.
- *
- * This method
- * simply performs in.reset().
- *
- * Stream marks are intended to be used in - * situations where you need to read ahead a little to see what's in - * the stream. Often this is most easily done by invoking some - * general parser. If the stream is of the type handled by the - * parse, it just chugs along happily. If the stream is not of - * that type, the parser should toss an exception when it fails. - * If this happens within readlimit bytes, it allows the outer - * code to reset the stream and try another parser. - * - * @exception IOException if the stream has not been marked or if the - * mark has been invalidated. - * @see java.io.FilterInputStream#in - * @see java.io.FilterInputStream#mark(int) - */ - public synchronized void reset() throws IOException { - in.reset(); - } - - -} diff --git a/src/zutil/io/BufferedRandomAccessFile.java b/src/zutil/io/BufferedRandomAccessFile.java index 7c6f0c6..437bec3 100644 --- a/src/zutil/io/BufferedRandomAccessFile.java +++ b/src/zutil/io/BufferedRandomAccessFile.java @@ -12,8 +12,8 @@ import java.io.RandomAccessFile; * @author Ziver */ public class BufferedRandomAccessFile extends RandomAccessFile{ - // The size of the buffer - private int BUF_SIZE = 256; + // The size of the buffer in Byte + private int BUF_SIZE = 64*1024; // The Buffer byte buffer[]; @@ -73,22 +73,6 @@ public class BufferedRandomAccessFile extends RandomAccessFile{ buffer = new byte[BUF_SIZE]; } - /** - * @return the next byte in the buffer - */ - public final int read() throws IOException{ - if(buf_pos >= buf_end) { - if(fillBuffer() < 0) - return -1; - } - if(buf_end == 0) { - return -1; - } else { - buf_pos++; - return buffer[buf_pos-1]; - } - } - /** * Reads in data from the file to the buffer * @@ -116,6 +100,22 @@ public class BufferedRandomAccessFile extends RandomAccessFile{ file_pos = super.getFilePointer(); } + /** + * @return the next byte in the buffer + */ + public final int read() throws IOException{ + if(buf_pos >= buf_end) { + if(fillBuffer() < 0) + return -1; + } + if(buf_end == 0) { + return -1; + } else { + buf_pos++; + return buffer[buf_pos-1]; + } + } + /** * Fills the given array with data from the buffer * @@ -135,13 +135,26 @@ public class BufferedRandomAccessFile extends RandomAccessFile{ * @return the amount of bytes read or -1 if eof */ public int read(byte b[], int off, int len) throws IOException { + if(buf_pos >= buf_end) { + if(fillBuffer() < 0) + return -1; // EOF + } + + // Copy from buffer int leftover = buf_end - buf_pos; if(len <= leftover) { System.arraycopy(buffer, buf_pos, b, off, len); buf_pos += len; return len; } - for(int i = 0; i < len; i++) { + + System.arraycopy(buffer, buf_pos, b, off, leftover); + int n = super.read(b, off+leftover, len-leftover ); + fillBuffer(); + if( n >= 0 ) + return leftover + n; + return leftover; + /*for(int i = 0; i < len; i++) { int c = this.read(); if(c != -1) b[off+i] = (byte)c; @@ -149,7 +162,7 @@ public class BufferedRandomAccessFile extends RandomAccessFile{ return i; } } - return len; + return len;*/ } /** diff --git a/src/zutil/struct/DynamicByteArrayStream.java b/src/zutil/io/DynamicByteArrayStream.java similarity index 95% rename from src/zutil/struct/DynamicByteArrayStream.java rename to src/zutil/io/DynamicByteArrayStream.java index 7b89af8..25b57c1 100644 --- a/src/zutil/struct/DynamicByteArrayStream.java +++ b/src/zutil/io/DynamicByteArrayStream.java @@ -1,4 +1,4 @@ -package zutil.struct; +package zutil.io; import java.io.IOException; import java.io.InputStream;