static byte[] readFastOrFail(boolean silent) throws IOException, Error
{
ExtendedInputStream in = null; //assuming initializtion here
final long start = currentTimeMillis();
final byte[] data = new byte[1024*1024];
// Caution: 'final int' forced by declaration,
// that means 'numBytesRead = ..' is not possible.
int read = in.readFully(final int numBytesRead : data)
{
if( ( currentTimeMillis() - start) > 1000*numBytesRead)
{
if(silent) return null; // return from readFast
else throw new Error("Reading was too slow") ?; // throws out of readFast
}
}
// the compile-time error: 'variable might not have been initialized'
// because 'break' (or 'result') statement has been used inside the block.
// Solution: int read = -1; read = in.readFully(int read : data) { ... }
assert( data.length == read );
return data;
}