From 58a311381994b1fc3bfe0348095d865ca0c0e98a Mon Sep 17 00:00:00 2001 From: Ziver Koc Date: Fri, 13 Aug 2010 22:27:55 +0000 Subject: [PATCH] moved some files and fixed javadoc --- src/zutil/Dumpable.java | 2 +- src/zutil/ProgressListener.java | 10 +- src/zutil/io/BoundryBufferedInputStream.java | 91 +++++++++++++++++++ .../BufferedRandomAccessFile.java | 62 ++++++++++--- .../{wrapper => io}/StringOutputStream.java | 2 +- 5 files changed, 147 insertions(+), 20 deletions(-) create mode 100644 src/zutil/io/BoundryBufferedInputStream.java rename src/zutil/{wrapper => io}/BufferedRandomAccessFile.java (66%) rename src/zutil/{wrapper => io}/StringOutputStream.java (91%) diff --git a/src/zutil/Dumpable.java b/src/zutil/Dumpable.java index c5fcf87..2fc0b0d 100644 --- a/src/zutil/Dumpable.java +++ b/src/zutil/Dumpable.java @@ -2,7 +2,7 @@ package zutil; /** * If an class implements this interface and runs it through - * MultiPrintStream.dump then all the values in the object + * MultiPrintStream.dump() then all the values in the object * will be written out. * * @author Ziver diff --git a/src/zutil/ProgressListener.java b/src/zutil/ProgressListener.java index d661831..e3c0f85 100644 --- a/src/zutil/ProgressListener.java +++ b/src/zutil/ProgressListener.java @@ -7,12 +7,14 @@ package zutil; * @author Ziver * */ -public interface ProgressListener { +public interface ProgressListener { /** * This method is called when the progress is updated - * @param source The source object of the progress - * @param percent The progress of the object (0-100) + * + * @param source is the source object of the progress + * @param info is some information from the source object + * @param percent is the progress of the object (0-100) */ - public void progressUpdate(Object source, Object info, double percent); + public void progressUpdate(Object source, T info, double percent); } diff --git a/src/zutil/io/BoundryBufferedInputStream.java b/src/zutil/io/BoundryBufferedInputStream.java new file mode 100644 index 0000000..880b6eb --- /dev/null +++ b/src/zutil/io/BoundryBufferedInputStream.java @@ -0,0 +1,91 @@ +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/wrapper/BufferedRandomAccessFile.java b/src/zutil/io/BufferedRandomAccessFile.java similarity index 66% rename from src/zutil/wrapper/BufferedRandomAccessFile.java rename to src/zutil/io/BufferedRandomAccessFile.java index 4386b71..7c6f0c6 100644 --- a/src/zutil/wrapper/BufferedRandomAccessFile.java +++ b/src/zutil/io/BufferedRandomAccessFile.java @@ -1,4 +1,4 @@ -package zutil.wrapper; +package zutil.io; import java.io.File; import java.io.IOException; @@ -22,33 +22,59 @@ public class BufferedRandomAccessFile extends RandomAccessFile{ // The position in the buffer int buf_pos = 0; // The real file pointer position where the buffer starts - long real_pos = 0; + long file_pos = 0; - + /** + * Create a instance of this buffer + * + * @param filename is the file to read from + * @param mode as in {@link java.io.RandomAccessFile#RandomAccessFile(File file, String mode)} + */ public BufferedRandomAccessFile(String filename, String mode) throws IOException{ this(new File(filename), mode); } + /** + * Create a instance of this buffer + * + * @param file is the file to read from + * @param mode as in {@link java.io.RandomAccessFile#RandomAccessFile(File file, String mode)} + */ public BufferedRandomAccessFile(File file, String mode) throws IOException{ super(file,mode); invalidate(); buffer = new byte[BUF_SIZE]; } + /** + * Create a instance of this buffer + * + * @param filename is the file to read from + * @param mode as in {@link java.io.RandomAccessFile#RandomAccessFile(File file, String mode)} + * @param bufsize is the buffer size in bytes + * @throws IOException + */ public BufferedRandomAccessFile(String filename, String mode, int bufsize) throws IOException{ this(new File(filename), mode, bufsize); } + /** + * Create a instance of this buffer + * + * @param file is the file to read from + * @param mode as in {@link java.io.RandomAccessFile#RandomAccessFile(File file, String mode)} + * @param bufsize is the buffer size in bytes + * @throws IOException + */ public BufferedRandomAccessFile(File file, String mode, int bufsize) throws IOException{ super(file,mode); invalidate(); BUF_SIZE = bufsize; - buffer = new byte[BUF_SIZE]; + buffer = new byte[BUF_SIZE]; } /** - * Reads the next byte in the buffer - * + * @return the next byte in the buffer */ public final int read() throws IOException{ if(buf_pos >= buf_end) { @@ -66,13 +92,13 @@ public class BufferedRandomAccessFile extends RandomAccessFile{ /** * Reads in data from the file to the buffer * - * @return The buffer + * @return the buffer * @throws IOException */ private int fillBuffer() throws IOException { int n = super.read(buffer, 0, BUF_SIZE ); if(n >= 0) { - real_pos +=n; + file_pos +=n; buf_end = n; buf_pos = 0; } @@ -87,11 +113,14 @@ public class BufferedRandomAccessFile extends RandomAccessFile{ private void invalidate() throws IOException { buf_end = 0; buf_pos = 0; - real_pos = super.getFilePointer(); + file_pos = super.getFilePointer(); } /** - * This class while read in b.length from the file + * Fills the given array with data from the buffer + * + * @param b is the array that will be filled + * @return the amount of bytes read or -1 if eof */ public int read(byte b[]) throws IOException { return read(b, 0, b.length); @@ -100,6 +129,10 @@ public class BufferedRandomAccessFile extends RandomAccessFile{ /** * Reads a given length of bytes from the buffer * + * @param b is the array that will be filled + * @param off is the offset in the array + * @param len is the amount to read + * @return the amount of bytes read or -1 if eof */ public int read(byte b[], int off, int len) throws IOException { int leftover = buf_end - buf_pos; @@ -120,10 +153,10 @@ public class BufferedRandomAccessFile extends RandomAccessFile{ } /** - * Returns the file pointer in the file + * @return the file pointer in the file */ public long getFilePointer() throws IOException{ - long l = real_pos; + long l = file_pos; return (l - buf_end + buf_pos) ; } @@ -133,7 +166,7 @@ public class BufferedRandomAccessFile extends RandomAccessFile{ * @param pos The position to move the pointer to */ public void seek(long pos) throws IOException { - int n = (int)(real_pos - pos); + int n = (int)(file_pos - pos); if(n >= 0 && n <= buf_end) { buf_pos = buf_end - n; } else { @@ -143,8 +176,9 @@ public class BufferedRandomAccessFile extends RandomAccessFile{ } /** - * Returns the next line in the file * This method is a replacement for readLine() + * + * @return the next line in the file */ public final String readNextLine() throws IOException { String str = null; diff --git a/src/zutil/wrapper/StringOutputStream.java b/src/zutil/io/StringOutputStream.java similarity index 91% rename from src/zutil/wrapper/StringOutputStream.java rename to src/zutil/io/StringOutputStream.java index 8d98c30..2cb54c5 100644 --- a/src/zutil/wrapper/StringOutputStream.java +++ b/src/zutil/io/StringOutputStream.java @@ -1,4 +1,4 @@ -package zutil.wrapper; +package zutil.io; import java.io.OutputStream;