Removed constructors that take the "compressed" parameter (compression has been removed from the specification).

Added constructor that takes byte[], offset and length.
This commit is contained in:
Simone Bordet 2012-06-03 11:27:54 +02:00
parent f9a917f538
commit 4b29f18703
2 changed files with 17 additions and 17 deletions

View File

@ -23,39 +23,44 @@ import java.nio.ByteBuffer;
*/
public class BytesDataInfo extends DataInfo
{
private byte[] bytes;
private int offset;
private final byte[] bytes;
private final int offset;
private final int length;
private int index;
public BytesDataInfo(byte[] bytes, boolean close)
{
this(bytes, close, false);
this(bytes, 0, bytes.length, close);
}
public BytesDataInfo(byte[] bytes, boolean close, boolean compress)
public BytesDataInfo(byte[] bytes, int offset, int length, boolean close)
{
super(close, compress);
super(close, false);
this.bytes = bytes;
this.offset = offset;
this.length = length;
this.index = offset;
}
@Override
public int length()
{
return bytes.length;
return length;
}
@Override
public int available()
{
return length() - offset;
return length - index + offset;
}
@Override
public int readInto(ByteBuffer output)
{
int space = output.remaining();
int length = Math.min(available(), space);
output.put(bytes, offset, length);
offset += length;
return length;
int chunk = Math.min(available(), space);
output.put(bytes, index, chunk);
index += chunk;
return chunk;
}
}

View File

@ -25,11 +25,6 @@ public class StringDataInfo extends BytesDataInfo
{
public StringDataInfo(String string, boolean close)
{
this(string, close, false);
}
public StringDataInfo(String string, boolean close, boolean compress)
{
super(string.getBytes(Charset.forName("UTF-8")), close, compress);
super(string.getBytes(Charset.forName("UTF-8")), close);
}
}