From: Bryan T. <tho...@us...> - 2008-10-09 13:13:47
|
Update of /cvsroot/cweb/lgpl-utils/src/java/it/unimi/dsi/mg4j/io In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv25575/src/java/it/unimi/dsi/mg4j/io Modified Files: OutputBitStream.java InputBitStream.java Log Message: Done. Modified InputBitStream and OutputBitStream to have ctor variants that avoid a reflection test on the underlying stream. This was causing approximately 5000 MethodNotFoundException instances to be thrown per second. Introduced a new lgpl-utils jar for this change (1.1-b3). The change will be rolled into dsiutils by its author. Index: OutputBitStream.java =================================================================== RCS file: /cvsroot/cweb/lgpl-utils/src/java/it/unimi/dsi/mg4j/io/OutputBitStream.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** OutputBitStream.java 10 Jul 2007 16:12:56 -0000 1.1 --- OutputBitStream.java 9 Oct 2008 13:13:20 -0000 1.2 *************** *** 163,173 **** ! /** Creates a new output bit stream wrapping a given output stream with a specified buffer size. * * @param os the output stream to wrap. * @param bufSize the size in byte of the buffer; it may be 0, denoting no buffering. */ ! public OutputBitStream( final OutputStream os, final int bufSize ) { this.os = os; if ( bufSize != 0 ) { --- 163,189 ---- ! /** Creates a new output bit stream wrapping a given output stream with a specified buffer size. ! * ! * @param os the output stream to wrap. ! * @param bufSize the size in byte of the buffer; it may be 0, denoting no buffering. ! */ ! public OutputBitStream( final OutputStream os, final int bufSize ) { ! this( os, bufSize, true/*reflectionTest*/); ! } ! /** Creates a new output bit stream wrapping a given output stream with a specified buffer size. * * @param os the output stream to wrap. * @param bufSize the size in byte of the buffer; it may be 0, denoting no buffering. + * @param reflectionTest + * when <code>true</code>, an instance of this class will try + * to cast the underlying byte stream to a + * {@link RepositionableStream} and to fetch by reflection the + * {@link java.nio.channels.FileChannel} underlying the given + * input stream, in this order (the traditional behavior). When + * <code>false</code> the reflection test will not be made in + * order to reduce the overhead of the ctor. */ ! public OutputBitStream( final OutputStream os, final int bufSize, final boolean reflectionTest ) { this.os = os; if ( bufSize != 0 ) { *************** *** 178,182 **** if ( os instanceof RepositionableStream ) repositionableStream = (RepositionableStream)os; ! if ( repositionableStream == null ) { try { --- 194,199 ---- if ( os instanceof RepositionableStream ) repositionableStream = (RepositionableStream)os; ! ! if(reflectionTest) { if ( repositionableStream == null ) { try { *************** *** 189,192 **** --- 206,210 ---- catch( ClassCastException e ) {} } + } } Index: InputBitStream.java =================================================================== RCS file: /cvsroot/cweb/lgpl-utils/src/java/it/unimi/dsi/mg4j/io/InputBitStream.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** InputBitStream.java 10 Jul 2007 16:12:56 -0000 1.1 --- InputBitStream.java 9 Oct 2008 13:13:20 -0000 1.2 *************** *** 207,211 **** * @param bufSize the size in byte of the buffer; it may be 0, denoting no buffering. */ ! public InputBitStream( final InputStream is, final int bufSize ) { this.is = is; if ( ! ( this.noBuffer = bufSize == 0 ) ) this.buffer = new byte[ bufSize ]; --- 207,235 ---- * @param bufSize the size in byte of the buffer; it may be 0, denoting no buffering. */ ! public InputBitStream(final InputStream is, final int bufSize) { ! ! this(is, bufSize, true/* reflectionTest */); ! ! } ! ! /** ! * Creates a new input bit stream wrapping a given input stream with a ! * specified buffer size. ! * ! * @param is ! * the input stream to wrap. ! * @param bufSize ! * the size in byte of the buffer; it may be 0, denoting no ! * buffering. ! * @param reflectionTest ! * when <code>true</code>, an instance of this class will try ! * to cast the underlying byte stream to a ! * {@link RepositionableStream} and to fetch by reflection the ! * {@link java.nio.channels.FileChannel} underlying the given ! * input stream, in this order (the traditional behavior). When ! * <code>false</code> the reflection test will not be made in ! * order to reduce the overhead of the ctor. ! */ ! public InputBitStream( final InputStream is, final int bufSize,final boolean reflectionTest ) { this.is = is; if ( ! ( this.noBuffer = bufSize == 0 ) ) this.buffer = new byte[ bufSize ]; *************** *** 213,216 **** --- 237,241 ---- if ( is instanceof RepositionableStream ) repositionableStream = (RepositionableStream)is; + if(reflectionTest) { if ( repositionableStream == null ) { try { *************** *** 223,226 **** --- 248,252 ---- catch( ClassCastException e ) {} } + } } |