Various code fixes (#3704)
Correctly close streams. Avoid ArithmeticException in case of /0.
This commit is contained in:
@@ -84,7 +84,7 @@ public class PacketMEFluidInventoryUpdate extends AppEngPacket
|
||||
|
||||
// int originalBytes = stream.readableBytes();
|
||||
|
||||
final GZIPInputStream gzReader = new GZIPInputStream( new InputStream()
|
||||
try( final GZIPInputStream gzReader = new GZIPInputStream( new InputStream()
|
||||
{
|
||||
@Override
|
||||
public int read() throws IOException
|
||||
@@ -96,26 +96,26 @@ public class PacketMEFluidInventoryUpdate extends AppEngPacket
|
||||
|
||||
return stream.readByte() & STREAM_MASK;
|
||||
}
|
||||
} );
|
||||
|
||||
final ByteBuf uncompressed = Unpooled.buffer( stream.readableBytes() );
|
||||
final byte[] tmp = new byte[TEMP_BUFFER_SIZE];
|
||||
while( gzReader.available() != 0 )
|
||||
} ) )
|
||||
{
|
||||
final int bytes = gzReader.read( tmp );
|
||||
if( bytes > 0 )
|
||||
|
||||
final ByteBuf uncompressed = Unpooled.buffer( stream.readableBytes() );
|
||||
final byte[] tmp = new byte[TEMP_BUFFER_SIZE];
|
||||
|
||||
while( gzReader.available() != 0 )
|
||||
{
|
||||
uncompressed.writeBytes( tmp, 0, bytes );
|
||||
final int bytes = gzReader.read( tmp );
|
||||
|
||||
if( bytes > 0 )
|
||||
{
|
||||
uncompressed.writeBytes( tmp, 0, bytes );
|
||||
}
|
||||
}
|
||||
}
|
||||
gzReader.close();
|
||||
|
||||
// int uncompressedBytes = uncompressed.readableBytes();
|
||||
// AELog.info( "Receiver: " + originalBytes + " -> " + uncompressedBytes );
|
||||
|
||||
while( uncompressed.readableBytes() > 0 )
|
||||
{
|
||||
this.list.add( AEFluidStack.fromPacket( uncompressed ) );
|
||||
while( uncompressed.readableBytes() > 0 )
|
||||
{
|
||||
this.list.add( AEFluidStack.fromPacket( uncompressed ) );
|
||||
}
|
||||
}
|
||||
|
||||
this.empty = this.list.isEmpty();
|
||||
|
||||
@@ -82,7 +82,7 @@ public class PacketMEInventoryUpdate extends AppEngPacket
|
||||
|
||||
// int originalBytes = stream.readableBytes();
|
||||
|
||||
final GZIPInputStream gzReader = new GZIPInputStream( new InputStream()
|
||||
try( GZIPInputStream gzReader = new GZIPInputStream( new InputStream()
|
||||
{
|
||||
@Override
|
||||
public int read() throws IOException
|
||||
@@ -94,29 +94,29 @@ public class PacketMEInventoryUpdate extends AppEngPacket
|
||||
|
||||
return stream.readByte() & STREAM_MASK;
|
||||
}
|
||||
} );
|
||||
|
||||
final ByteBuf uncompressed = Unpooled.buffer( stream.readableBytes() );
|
||||
final byte[] tmp = new byte[TEMP_BUFFER_SIZE];
|
||||
while( gzReader.available() != 0 )
|
||||
} ) )
|
||||
{
|
||||
final int bytes = gzReader.read( tmp );
|
||||
if( bytes > 0 )
|
||||
final ByteBuf uncompressed = Unpooled.buffer( stream.readableBytes() );
|
||||
final byte[] tmp = new byte[TEMP_BUFFER_SIZE];
|
||||
|
||||
while( gzReader.available() != 0 )
|
||||
{
|
||||
uncompressed.writeBytes( tmp, 0, bytes );
|
||||
final int bytes = gzReader.read( tmp );
|
||||
|
||||
if( bytes > 0 )
|
||||
{
|
||||
uncompressed.writeBytes( tmp, 0, bytes );
|
||||
}
|
||||
}
|
||||
}
|
||||
gzReader.close();
|
||||
|
||||
// int uncompressedBytes = uncompressed.readableBytes();
|
||||
// AELog.info( "Receiver: " + originalBytes + " -> " + uncompressedBytes );
|
||||
|
||||
while( uncompressed.readableBytes() > 0 )
|
||||
{
|
||||
this.list.add( AEItemStack.fromPacket( uncompressed ) );
|
||||
while( uncompressed.readableBytes() > 0 )
|
||||
{
|
||||
this.list.add( AEItemStack.fromPacket( uncompressed ) );
|
||||
}
|
||||
}
|
||||
|
||||
this.empty = this.list.isEmpty();
|
||||
|
||||
}
|
||||
|
||||
// api
|
||||
|
||||
Reference in New Issue
Block a user