private String fixedSizeByteArrayAsHexString(int length){ byte[] bBinary = RandomUtils.nextBytes(length); return DatatypeConverter.printHexBinary(bBinary); }
private String fixedSizeByteArrayAsBase64String(int length){ byte[] bBinary = RandomUtils.nextBytes(length); return DatatypeConverter.printBase64Binary(bBinary); }
@Test(expected = IllegalArgumentException.class) public void testNextBytesNegative() throws Exception { RandomUtils.nextBytes(-1); }
@Test public void shortByteArrayIsValid() { validator.validate( RandomUtils.nextBytes( 3 ) ); validator.validate( RandomUtils.nextBytes( 30 ) ); validator.validate( RandomUtils.nextBytes( 300 ) ); validator.validate( RandomUtils.nextBytes( 4303 ) ); validator.validate( RandomUtils.nextBytes( 13234 ) ); validator.validate( RandomUtils.nextBytes( MAX_BYTE_LENGTH ) ); }
private String fixedSizeByteArrayAsASCIIString(int length){ byte[] bBinary = RandomUtils.nextBytes(length); ByteBuffer bytes = ByteBuffer.wrap(bBinary); StringBuffer sbBytes = new StringBuffer(); for (int i = bytes.position(); i < bytes.limit(); i++) sbBytes.append((char)bytes.get(i)); return sbBytes.toString(); }
@Before public void setUp() throws IOException { // Create a byte array of size 2 MB with random bytes randomBytes = RandomUtils.nextBytes(2 * 1024 * 1024); inputFile = File.createTempFile("temp-file", ".tmp"); FileUtils.writeByteArrayToFile(inputFile, randomBytes); }
@Before public void setUp() throws IOException { // Create a byte array of size 2 MB with random bytes randomBytes = RandomUtils.nextBytes(2 * 1024 * 1024); inputFile = File.createTempFile("temp-file", ".tmp"); FileUtils.writeByteArrayToFile(inputFile, randomBytes); }
@Before public void setUp() throws IOException { // Create a byte array of size 2 MB with random bytes randomBytes = RandomUtils.nextBytes(2 * 1024 * 1024); inputFile = File.createTempFile("temp-file", ".tmp"); FileUtils.writeByteArrayToFile(inputFile, randomBytes); }
/** * Tests a zero byte array length. */ @Test public void testZeroLengthNextBytes() { assertArrayEquals(new byte[0], RandomUtils.nextBytes(0)); }
/** * Tests random byte array. */ @Test public void testNextBytes() { final byte[] result = RandomUtils.nextBytes(20); assertEquals(20, result.length); }
@Test void tooLongArrayIsNotAllowed() { int length = MAX_TERM_LENGTH + 1; IllegalArgumentException iae = assertThrows( IllegalArgumentException.class, () -> getValidator().validate( RandomUtils.nextBytes( length ) ) ); assertThat( iae.getMessage(), containsString( "Property value size is too large for index. Please see index documentation for limitations." ) ); }
private static SegmentCommitInfo getSegmentCommitInfo() { SegmentInfo segmentInfo = new SegmentInfo( mock( Directory.class ), Version.LATEST, "test", Integer.MAX_VALUE, true, mock( Codec.class ), MapUtil.stringMap(), RandomUtils.nextBytes( 16 ), MapUtil.stringMap() ); return new SegmentCommitInfo( segmentInfo, 1, 1L, 1L, 1L ); }
@Test public void testRequire64CharsPrivateKey() { assertInvalidPrivateKey(RandomUtils.nextBytes(1)); assertInvalidPrivateKey(RandomUtils.nextBytes(31)); assertInvalidPrivateKey(RandomUtils.nextBytes(33)); assertInvalidPrivateKey(RandomUtils.nextBytes(64)); assertInvalidPrivateKey(RandomUtils.nextBytes(0)); String validPrivateKey = Hex.toHexString(RandomUtils.nextBytes(32)); SystemProperties props = new SystemProperties(); props.overrideParams("peer.privateKey", validPrivateKey); assertEquals(validPrivateKey, props.privateKey()); }
@Test public void tooLongByteArrayIsNotAllowed() { int length = MAX_BYTE_LENGTH * 2; expectedException.expect( IllegalArgumentException.class ); expectedException.expectMessage( containsString( "Property value size is too large for index. Please see index documentation for limitations." ) ); validator.validate( RandomUtils.nextBytes( length ) ); }
@Test public void testFastSyncPivotBlockHash() { SystemProperties props = new SystemProperties(); assertNull(props.getFastSyncPivotBlockHash()); byte[] validPivotBlockHash = RandomUtils.nextBytes(32); props.overrideParams("sync.fast.pivotBlockHash", Hex.toHexString(validPivotBlockHash)); assertTrue(Arrays.equals(validPivotBlockHash, props.getFastSyncPivotBlockHash())); assertInvalidPivotBlockHash(RandomUtils.nextBytes(0)); assertInvalidPivotBlockHash(RandomUtils.nextBytes(1)); assertInvalidPivotBlockHash(RandomUtils.nextBytes(31)); assertInvalidPivotBlockHash(RandomUtils.nextBytes(33)); }
@Test void shortArrayIsValidValue() { getValidator().validate( new long[] {1, 2, 3} ); getValidator().validate( RandomUtils.nextBytes( 200 ) ); }
private DynamicRecord createDynamicRecord( long id, AbstractDynamicStore store, int dataSize ) { DynamicRecord first = new DynamicRecord( id ); first.setInUse( true ); first.setData( RandomUtils.nextBytes( dataSize == 0 ? BLOCK_SIZE - formats.dynamic().getRecordHeaderSize() : 10 ) ); store.updateRecord( first ); return first; }
byte[] propertyValue = RandomUtils.nextBytes( 1024 );
byte[] propertyValue = RandomUtils.nextBytes( 1024 );