public void testMap() throws IOException { // Test data int size = 1024; byte[] bytes = newPreFilledByteArray(size); // Setup File file = createTempFile(); Files.write(bytes, file); // Test MappedByteBuffer actual = Files.map(file); // Verify ByteBuffer expected = ByteBuffer.wrap(bytes); assertTrue("ByteBuffers should be equal.", expected.equals(actual)); }
public void testWriteBytes() throws IOException { File temp = createTempFile(); byte[] data = newPreFilledByteArray(2000); Files.write(data, temp); assertTrue(Arrays.equals(data, Files.toByteArray(temp))); try { Files.write(null, temp); fail("expected exception"); } catch (NullPointerException expected) { } }
public void testMap_readWrite() throws IOException { // Test data int size = 1024; byte[] expectedBytes = new byte[size]; byte[] bytes = newPreFilledByteArray(1024); // Setup File file = createTempFile(); Files.write(bytes, file); Random random = new Random(); random.nextBytes(expectedBytes); // Test MappedByteBuffer map = Files.map(file, MapMode.READ_WRITE); map.put(expectedBytes); // Verify byte[] actualBytes = Files.toByteArray(file); assertTrue(Arrays.equals(expectedBytes, actualBytes)); }
public void testMap_readWrite_creates() throws IOException { // Test data int size = 1024; byte[] expectedBytes = newPreFilledByteArray(1024); // Setup File file = createTempFile(); boolean deleted = file.delete(); assertTrue(deleted); assertFalse(file.exists()); // Test MappedByteBuffer map = Files.map(file, MapMode.READ_WRITE, size); map.put(expectedBytes); // Verify assertTrue(file.exists()); assertTrue(file.isFile()); assertEquals(size, file.length()); byte[] actualBytes = Files.toByteArray(file); assertTrue(Arrays.equals(expectedBytes, actualBytes)); }
public void testMap() throws IOException { // Test data int size = 1024; byte[] bytes = newPreFilledByteArray(size); // Setup File file = createTempFile(); Files.write(bytes, file); // Test MappedByteBuffer actual = Files.map(file); // Verify ByteBuffer expected = ByteBuffer.wrap(bytes); assertTrue("ByteBuffers should be equal.", expected.equals(actual)); }
public void testWriteBytes() throws IOException { File temp = createTempFile(); byte[] data = newPreFilledByteArray(2000); Files.write(data, temp); assertTrue(Arrays.equals(data, Files.toByteArray(temp))); try { Files.write(null, temp); fail("expected exception"); } catch (NullPointerException expected) { } }
public void testMap_readWrite() throws IOException { // Test data int size = 1024; byte[] expectedBytes = new byte[size]; byte[] bytes = newPreFilledByteArray(1024); // Setup File file = createTempFile(); Files.write(bytes, file); Random random = new Random(); random.nextBytes(expectedBytes); // Test MappedByteBuffer map = Files.map(file, MapMode.READ_WRITE); map.put(expectedBytes); // Verify byte[] actualBytes = Files.toByteArray(file); assertTrue(Arrays.equals(expectedBytes, actualBytes)); }
public void testMap_readWrite_creates() throws IOException { // Test data int size = 1024; byte[] expectedBytes = newPreFilledByteArray(1024); // Setup File file = createTempFile(); boolean deleted = file.delete(); assertTrue(deleted); assertFalse(file.exists()); // Test MappedByteBuffer map = Files.map(file, MapMode.READ_WRITE, size); map.put(expectedBytes); // Verify assertTrue(file.exists()); assertTrue(file.isFile()); assertEquals(size, file.length()); byte[] actualBytes = Files.toByteArray(file); assertTrue(Arrays.equals(expectedBytes, actualBytes)); }