/** * Change the capacity of the backing storage. * The data is preserved if newCapacity >= getCount(). * @param newCapacity The new capacity in bytes. */ public void setCapacity(int newCapacity) { if (newCapacity < 0) { throw new IllegalArgumentException("Invalid capacity argument "+newCapacity); } if (newCapacity == 0) { this.bytes = null; this.count = 0; return; } if (newCapacity != getCapacity()) { byte[] data = new byte[newCapacity]; if (newCapacity < count) { count = newCapacity; } if (count != 0) { System.arraycopy(this.get(), 0, data, 0, count); } bytes = data; } }
/** * Change the capacity of the backing storage. * The data is preserved if newCapacity {@literal >=} getCount(). * @param newCapacity The new capacity in bytes. */ public void setCapacity(int newCapacity) { if (newCapacity < 0) { throw new IllegalArgumentException("Invalid capacity argument "+newCapacity); } if (newCapacity == 0) { this.bytes = null; this.count = 0; return; } if (newCapacity != getCapacity()) { byte[] data = new byte[newCapacity]; if (newCapacity < count) { count = newCapacity; } if (count != 0) { System.arraycopy(this.get(), 0, data, 0, count); } bytes = data; } }
/** * Change the capacity of the backing storage. * The data is preserved if newCapacity {@literal >=} getCount(). * @param newCapacity The new capacity in bytes. */ public void setCapacity(int newCapacity) { if (newCapacity < 0) { throw new IllegalArgumentException("Invalid capacity argument "+newCapacity); } if (newCapacity == 0) { this.bytes = null; this.count = 0; return; } if (newCapacity != getCapacity()) { byte[] data = new byte[newCapacity]; if (newCapacity < count) { count = newCapacity; } if (count != 0) { System.arraycopy(this.get(), 0, data, 0, count); } bytes = data; } }
/** * Change the capacity of the backing storage. * The data is preserved if newCapacity >= getCount(). * @param newCapacity The new capacity in bytes. */ public void setCapacity(int newCapacity) { if (newCapacity < 0) { throw new IllegalArgumentException("Invalid capacity argument "+newCapacity); } if (newCapacity == 0) { this.bytes = null; this.count = 0; return; } if (newCapacity != getCapacity()) { byte[] data = new byte[newCapacity]; if (newCapacity < count) { count = newCapacity; } if (count != 0) { System.arraycopy(this.get(), 0, data, 0, count); } bytes = data; } }
/** * Change the capacity of the backing storage. * The data is preserved if newCapacity {@literal >=} getCount(). * @param newCapacity The new capacity in bytes. */ public void setCapacity(int newCapacity) { if (newCapacity < 0) { throw new IllegalArgumentException("Invalid capacity argument "+newCapacity); } if (newCapacity == 0) { this.bytes = null; this.count = 0; return; } if (newCapacity != getCapacity()) { byte[] data = new byte[newCapacity]; if (newCapacity < count) { count = newCapacity; } if (count != 0) { System.arraycopy(this.get(), 0, data, 0, count); } bytes = data; } }
/** * Change the capacity of the backing storage. * The data is preserved if newCapacity {@literal >=} getCount(). * @param newCapacity The new capacity in bytes. */ public void setCapacity(int newCapacity) { if (newCapacity < 0) { throw new IllegalArgumentException("Invalid capacity argument "+newCapacity); } if (newCapacity == 0) { this.bytes = null; this.count = 0; return; } if (newCapacity != getCapacity()) { byte[] data = new byte[newCapacity]; if (newCapacity < count) { count = newCapacity; } if (count != 0) { System.arraycopy(this.get(), 0, data, 0, count); } bytes = data; } }
/** * Change the capacity of the backing storage. * The data is preserved if newCapacity {@literal >=} getCount(). * @param newCapacity The new capacity in bytes. */ public void setCapacity(int newCapacity) { if (newCapacity < 0) { throw new IllegalArgumentException("Invalid capacity argument "+newCapacity); } if (newCapacity == 0) { this.bytes = null; this.count = 0; return; } if (newCapacity != getCapacity()) { byte[] data = new byte[newCapacity]; if (newCapacity < count) { count = newCapacity; } if (count != 0) { System.arraycopy(this.get(), 0, data, 0, count); } bytes = data; } }
/** * Test of getCapacity method, of class org.apache.hadoop.record.Buffer. */ public void testGetCapacity() { final Buffer instance = new Buffer(); final int expResult = 0; final int result = instance.getCapacity(); assertEquals("getCapacity failed", expResult, result); instance.setCapacity(100); assertEquals("setCapacity failed", 100, instance.getCapacity()); }
/** * Test of truncate method, of class org.apache.hadoop.record.Buffer. */ public void testTruncate() { final Buffer instance = new Buffer(); instance.setCapacity(100); assertEquals("setCapacity failed", 100, instance.getCapacity()); instance.truncate(); assertEquals("truncate failed", 0, instance.getCapacity()); }
/** * Test of copy method, of class org.apache.hadoop.record.Buffer. */ public void testCopy() { final byte[] bytes = new byte[10]; final int offset = 6; final int length = 3; for (int idx = 0; idx < 10; idx ++) { bytes[idx] = (byte) idx; } final Buffer instance = new Buffer(); instance.copy(bytes, offset, length); assertEquals("copy failed", 3, instance.getCapacity()); assertEquals("copy failed", 3, instance.get().length); for (int idx = 0; idx < 3; idx++) { assertEquals("Buffer content corrupted", idx+6, instance.get()[idx]); } }