use of java.nio.ByteBuffer in project bazel by bazelbuild.
the class CentralDirectoryTest method testViewOf.
/**
* Test of viewOf method, of class CentralDirectory.
*/
@Test
public void testViewOf() {
ByteBuffer buffer = ByteBuffer.allocate(100).order(ByteOrder.LITTLE_ENDIAN);
for (int i = 0; i < 100; i++) {
buffer.put((byte) i);
}
buffer.position(20);
buffer.limit(90);
CentralDirectory view = CentralDirectory.viewOf(buffer);
int expPos = 0;
int expLimit = 90;
// expect the buffer to have been reset to 0 (CentralDirectory does NOT slice).
assertEquals("View not at position 0", expPos, view.buffer.position());
assertEquals("Buffer not at position 0", expPos, buffer.position());
assertEquals("Buffer limit changed", expLimit, view.buffer.limit());
assertEquals("Buffer limit changed", expLimit, buffer.limit());
}
use of java.nio.ByteBuffer in project bazel by bazelbuild.
the class DirectoryEntryTest method testCopy.
/**
* Test of copy method, of class DirectoryEntry.
*/
@Test
public void testCopy() {
String filename = "pkg/foo.class";
byte[] extraData = {};
String comment = "always comment!";
ByteBuffer buffer = ByteBuffer.allocate(100).order(ByteOrder.LITTLE_ENDIAN);
DirectoryEntry view = DirectoryEntry.allocate(filename, extraData, comment);
view.copy(buffer);
int expSize = view.getSize();
assertEquals("buffer not advanced as expected", expSize, buffer.position());
buffer.position(0);
DirectoryEntry clone = DirectoryEntry.viewOf(buffer);
assertEquals("Fail to copy mark", view.get(CENSIG), clone.get(CENSIG));
assertEquals("Fail to copy comment", view.getFilename(), clone.getFilename());
Assert.assertArrayEquals("Fail to copy comment", view.getExtraData(), clone.getExtraData());
assertEquals("Fail to copy comment", view.getComment(), clone.getComment());
}
use of java.nio.ByteBuffer in project bazel by bazelbuild.
the class DirectoryEntryTest method testView_4Args.
/**
* Test of view method, of class DirectoryEntry.
*/
@Test
public void testView_4Args() {
ByteBuffer buffer = ByteBuffer.allocate(100).order(ByteOrder.LITTLE_ENDIAN);
for (int i = 0; i < 100; i++) {
buffer.put((byte) i);
}
int offset = 20;
buffer.position(offset);
String filename = "pkg/foo.class";
byte[] extraData = { 1, 2, 3, 4, 5 };
String comment = "c";
int expMark = (int) ZipInputStream.CENSIG;
int expSize = 46 + filename.getBytes(UTF_8).length + extraData.length + comment.getBytes(UTF_8).length;
int expPos = 0;
DirectoryEntry view = DirectoryEntry.view(buffer, filename, extraData, comment);
assertEquals("not based at current position", expMark, view.get(CENSIG));
assertEquals("Not slice with position 0", expPos, view.buffer.position());
assertEquals("Not sized with filename", expSize, view.getSize());
assertEquals("Not limited to size", expSize, view.buffer.limit());
assertEquals("Incorrect filename", filename, view.getFilename());
Assert.assertArrayEquals("Incorrect extra data", extraData, view.getExtraData());
assertEquals("Incorrect comment", comment, view.getComment());
}
use of java.nio.ByteBuffer in project bazel by bazelbuild.
the class LocalFileHeaderTest method testCopy.
@Test
public void testCopy() {
ByteBuffer buffer = ByteBuffer.allocate(100).order(ByteOrder.LITTLE_ENDIAN);
LocalFileHeader view = LocalFileHeader.allocate("pkg/foo.class", null);
view.copy(buffer);
int expSize = view.getSize();
assertEquals("buffer not advanced as expected", expSize, buffer.position());
buffer.position(0);
LocalFileHeader clone = LocalFileHeader.viewOf(buffer);
assertEquals("Fail to copy mark", view.get(LOCSIG), view.get(LOCSIG));
assertEquals("Fail to copy comment", view.getFilename(), clone.getFilename());
}
use of java.nio.ByteBuffer in project bazel by bazelbuild.
the class ViewTest method testFileOffset.
@Test
public void testFileOffset() {
ByteBuffer buffer = ByteBuffer.allocate(100);
TestView instance = new TestView(buffer);
long expResult = -1L;
long result = instance.fileOffset();
assertEquals("default file offset should be -1", expResult, result);
}
Aggregations