Buggy code:
abstract class SQLBinary extends DataType implements BitDataValue { static final byte PAD = ( ( byte ) ( 32 ) ) ; private static final int BASE_MEMORY_USAGE = ClassSize . estimateBaseFromCatalog ( SQLBinary . class ) ; public int estimateMemoryUsage ( ) { } abstract int getMaxMemoryUsage ( ) { } byte [ ] dataValue ; InputStream stream ; int streamValueLength ; SQLBinary ( ) { } SQLBinary ( byte [ ] val ) { } public final void setValue ( byte [ ] theValue ) { } public final String getString ( ) throws StandardException { } public final InputStream getStream ( ) { } public final byte [ ] getBytes ( ) throws StandardException { } byte [ ] getValue ( ) throws StandardException { } public final int getLength ( ) throws StandardException { } public final boolean isNull ( ) { } public final void writeExternal ( ObjectOutput out ) throws IOException { } public final void readExternal ( ObjectInput in ) throws IOException { } public final void readExternalFromArray ( ArrayInputStream in ) throws IOException { } private static int readBinaryLength ( ObjectInput in ) throws IOException { } private void readFromStream ( InputStream in ) throws IOException { dataValue = null ; byte [ ] tmpData = new byte [ 32 * 1024 ] ; int off = 0 ; for ( ; ; ) { int len = in . read ( tmpData , off , ( ( tmpData . length ) - off ) ) ; if ( len == ( - 1 ) ) break ; off += len ; <START_BUG> int available = in . available ( ) ; <END_BUG> int extraSpace = available - ( ( tmpData . length ) - off ) ; if ( extraSpace > 0 ) { int size = ( tmpData . length ) * 2 ; if ( extraSpace > ( tmpData . length ) ) size += extraSpace ; byte [ ] grow = new byte [ size ] ; System . arraycopy ( tmpData , 0 , grow , 0 , off ) ; tmpData = grow ; } } dataValue = new byte [ off ] ; System . arraycopy ( tmpData , 0 , dataValue , 0 , off ) ; } public final void restoreToNull ( ) { } public final boolean compare ( int op , DataValueDescriptor other , boolean orderedNulls , boolean unknownRV ) throws StandardException { } public final int compare ( DataValueDescriptor other ) throws StandardException { } public final Object cloneObject ( ) { } public final DataValueDescriptor getClone ( ) { } public final InputStream returnStream ( ) { } public final void setStream ( InputStream newStream ) { } public final void loadStream ( ) throws StandardException { } boolean objectNull ( Object o ) { } public final void setValue ( InputStream theStream , int valueLength ) { } protected final void setFrom ( DataValueDescriptor theValue ) throws StandardException { } public final BooleanDataValue equals ( DataValueDescriptor left , DataValueDescriptor right ) throws StandardException { } public final BooleanDataValue notEquals ( DataValueDescriptor left , DataValueDescriptor right ) throws StandardException { } public final BooleanDataValue lessThan ( DataValueDescriptor left , DataValueDescriptor right ) throws StandardException { } public final BooleanDataValue greaterThan ( DataValueDescriptor left , DataValueDescriptor right ) throws StandardException { } public final BooleanDataValue lessOrEquals ( DataValueDescriptor left , DataValueDescriptor right ) throws StandardException { } public final BooleanDataValue greaterOrEquals ( DataValueDescriptor left , DataValueDescriptor right ) throws StandardException { } public final NumberDataValue charLength ( NumberDataValue result ) throws StandardException { } public final BitDataValue concatenate ( BitDataValue left , BitDataValue right , BitDataValue result ) throws StandardException { } public final ConcatableDataValue substring ( NumberDataValue start , NumberDataValue length , ConcatableDataValue result , int maxLen ) throws StandardException { } public final void checkHostVariable ( int declaredLength ) throws StandardException { } public final String toString ( ) { } public final int hashCode ( ) { } private static int compare ( byte [ ] left , byte [ ] right ) { } public void setInto ( PreparedStatement ps , int position ) throws SQLException , StandardException { } }

Fix:
int available = Math . max ( 1 , in . available ( ) ) ;