diff --git a/.classpath b/.classpath index 19e0e62..0136fe4 100644 --- a/.classpath +++ b/.classpath @@ -4,7 +4,9 @@ - + + + diff --git a/libs/javassist.jar b/libs/javassist.jar new file mode 100644 index 0000000..29079c4 Binary files /dev/null and b/libs/javassist.jar differ diff --git a/src/zutil/converters/Converter.java b/src/zutil/converters/Converter.java index b3c4f45..19ffa6a 100644 --- a/src/zutil/converters/Converter.java +++ b/src/zutil/converters/Converter.java @@ -7,7 +7,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.BitSet; -import zutil.struct.DynamicByteArrayStream; +import zutil.io.DynamicByteArrayStream; public class Converter { private Converter(){} diff --git a/src/zutil/io/BoundryBufferedInputStream.java b/src/zutil/io/BoundryBufferedInputStream.java deleted file mode 100644 index 880b6eb..0000000 --- a/src/zutil/io/BoundryBufferedInputStream.java +++ /dev/null @@ -1,91 +0,0 @@ -package zutil.io; - -import java.io.FilterInputStream; -import java.io.IOException; -import java.io.InputStream; - -public class BoundryBufferedInputStream extends FilterInputStream{ - - protected BoundryBufferedInputStream(InputStream in) { - super(in); - } - - - public int read() throws IOException { - return in.read(); - } - - public int read(byte b[], int off, int len) throws IOException { - return in.read(b, off, len); - } - - public long skip(long n) throws IOException { - return in.skip(n); - } - - /** - * Returns an estimate of the number of bytes that can be read (or - * skipped over) from this input stream without blocking by the next - * caller of a method for this input stream. The next caller might be - * the same thread or another thread. A single read or skip of this - * many bytes will not block, but may read or skip fewer bytes. - *

- * 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;