Update of /var/cvs/src/org/mmbase/util In directory james.mmbase.org:/tmp/cvs-serv23894
Modified Files: SerializableInputStream.java Log Message: added a few constructors and methods See also: http://cvs.mmbase.org/viewcvs/src/org/mmbase/util Index: SerializableInputStream.java =================================================================== RCS file: /var/cvs/src/org/mmbase/util/SerializableInputStream.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -b -r1.1 -r1.2 --- SerializableInputStream.java 8 Jul 2008 07:36:48 -0000 1.1 +++ SerializableInputStream.java 16 Apr 2009 13:46:11 -0000 1.2 @@ -18,14 +18,20 @@ * another InputStream. * @since MMBase-1.9 * @author Michiel Meeuwissen - * @version $Id: SerializableInputStream.java,v 1.1 2008/07/08 07:36:48 michiel Exp $ + * @version $Id: SerializableInputStream.java,v 1.2 2009/04/16 13:46:11 michiel Exp $ * @todo IllegalStateException or so, if the inputstreas is used (already). */ public class SerializableInputStream extends InputStream implements Serializable { + private static final long serialVersionUID = 1; + private static final Logger log = Logging.getLoggerInstance(SerializableInputStream.class); + private final long size; + + private boolean used = false; + public static byte[] toByteArray(InputStream stream) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { @@ -40,10 +46,30 @@ return bos.toByteArray(); } + private void use() { + if (! used) { + if (log.isTraceEnabled()) { + log.trace("Using " + this + " because ", new Exception()); + } + used = true; + } + } + + private InputStream wrapped; - public SerializableInputStream(InputStream wrapped) { + public SerializableInputStream(InputStream wrapped, long s) { this.wrapped = wrapped; + this.size = s; + } + + public SerializableInputStream(byte[] array) { + this.wrapped = new ByteArrayInputStream(array); + this.size = array.length; + } + + public long getSize() { + return size; } private void writeObject(java.io.ObjectOutputStream out) throws IOException { @@ -57,9 +83,13 @@ public int available() throws IOException { return wrapped.available(); } public void mark(int readlimit) { wrapped.mark(readlimit); } public boolean markSupported() { return wrapped.markSupported(); } - public int read() throws IOException { return wrapped.read(); } - public int read(byte[] b) throws IOException { return wrapped.read(b); } - public int read(byte[] b, int off, int len) throws IOException { return wrapped.read(b, off, len); } + public int read() throws IOException { use(); return wrapped.read(); } + public int read(byte[] b) throws IOException { use(); return wrapped.read(b); } + public int read(byte[] b, int off, int len) throws IOException { use(); return wrapped.read(b, off, len); } public void reset() throws IOException { wrapped.reset() ; } public long skip(long n) throws IOException { return wrapped.skip(n); } + + public String toString() { + return "SERIALIZABLE " + wrapped + (used ? " (used)" : ""); + } } \ No newline at end of file _______________________________________________ Cvs mailing list Cvs@lists.mmbase.org http://lists.mmbase.org/mailman/listinfo/cvs