@@ -66,33 +66,34 @@ public void rewind () {
66
66
}
67
67
68
68
protected int fill (byte [] buffer , int offset , int count ) throws KryoException {
69
- if (chunkSize == -1 ) // No current chunk, expect a new chunk.
70
- readChunkSize ();
71
- else if (chunkSize == 0 ) // End of chunks .
69
+ if (chunkSize == -1 ) { // No current chunk, expect a new chunk.
70
+ if (! readChunkSize ()) return - 1 ;
71
+ } else if (chunkSize == 0 ) // End of chunk .
72
72
return -1 ;
73
73
int actual = super .fill (buffer , offset , Math .min (chunkSize , count ));
74
74
chunkSize -= actual ;
75
- if (chunkSize == 0 ) readChunkSize (); // Read next chunk size.
75
+ if (chunkSize == 0 && ! readChunkSize ()) return - 1 ;
76
76
return actual ;
77
77
}
78
78
79
- private void readChunkSize () {
79
+ /** @return false if the end of the stream was reached. */
80
+ private boolean readChunkSize () {
80
81
try {
81
82
InputStream inputStream = getInputStream ();
82
83
for (int offset = 0 , result = 0 ; offset < 32 ; offset += 7 ) {
83
84
int b = inputStream .read ();
84
- if (b == -1 ) throw new KryoException ( "Buffer underflow." ) ;
85
+ if (b == -1 ) return false ;
85
86
result |= (b & 0x7F ) << offset ;
86
87
if ((b & 0x80 ) == 0 ) {
87
88
chunkSize = result ;
88
- if (TRACE ) trace ("kryo" , "Read chunk: " + chunkSize );
89
- return ;
89
+ if (TRACE && chunkSize > 0 ) trace ("kryo" , "Read chunk: " + chunkSize );
90
+ return true ;
90
91
}
91
92
}
92
93
} catch (IOException ex ) {
93
- throw new KryoException (ex );
94
+ throw new KryoException ("Unable to read chunk size." , ex );
94
95
}
95
- throw new KryoException ("Malformed integer. " );
96
+ throw new KryoException ("Unable to read chunk size: malformed integer" );
96
97
}
97
98
98
99
/** Advances the stream to the next set of chunks. InputChunked will appear to hit the end of the data until this method is
0 commit comments