List of usage examples for java.util Random nextBytes
public void nextBytes(byte[] bytes)
From source file:com.funambol.foundation.util.FileDataObjectHelper.java
private byte[] createRandomByteArray(int fileSize) { byte[] dummyByteArray = new byte[fileSize]; // for (int i = 0; i < fileSize; i++) { // dummyByteArray[i] = (byte) (fileSize - i); // }//from ww w .j ava 2s .c om Random rand = new Random(); rand.nextBytes(dummyByteArray); return dummyByteArray; }
From source file:com.intel.chimera.CryptoCodecTest.java
@Before public void setUp() throws IOException { Random random = new SecureRandom(); random.nextBytes(key); random.nextBytes(iv);// w w w . j a v a 2 s . c o m props = new Properties(); }
From source file:org.apache.cassandra.db.marshal.TypeCompareTest.java
License:asdf
@Test public void testLong() { Random rng = new Random(); byte[][] data = new byte[1000][]; for (int i = 0; i < data.length; i++) { data[i] = new byte[8]; rng.nextBytes(data[i]); }/* w w w . j a v a 2 s . c o m*/ Arrays.sort(data, LongType.instance); for (int i = 1; i < data.length; i++) { long l0 = ByteBuffer.wrap(data[i - 1]).getLong(); long l1 = ByteBuffer.wrap(data[i]).getLong(); assert l0 <= l1; } }
From source file:org.apache.wink.itest.standard.JAXRSReaderTest.java
/** * Tests a resource method invoked with a BufferedReader as a parameter. * This should fail with a 415 since the reader has no way to necessarily * wrap it to the type./*from ww w .j av a 2 s. c o m*/ * * @throws HttpException * @throws IOException */ public void testInputStreamImplementation() throws HttpException, IOException { HttpClient client = new HttpClient(); PostMethod postMethod = new PostMethod(getBaseURI() + "/providers/standard/reader/subclasses/shouldfail"); byte[] barr = new byte[1000]; Random r = new Random(); r.nextBytes(barr); postMethod.setRequestEntity(new InputStreamRequestEntity(new ByteArrayInputStream(barr), "any/type")); try { client.executeMethod(postMethod); assertEquals(415, postMethod.getStatusCode()); } finally { postMethod.releaseConnection(); } }
From source file:org.apache.hadoop.hdfs.TestFileStatus.java
private void writeFile(FileSystem fileSys, Path name, int repl, int fileSize, int blockSize) throws IOException { // create and write a file that contains three blocks of data FSDataOutputStream stm = fileSys.create(name, true, fileSys.getConf().getInt("io.file.buffer.size", 4096), (short) repl, (long) blockSize); byte[] buffer = new byte[fileSize]; Random rand = new Random(seed); rand.nextBytes(buffer); stm.write(buffer);/*ww w .j av a2 s . co m*/ stm.close(); }
From source file:org.apache.weasel.V06Handshake.java
private String generateKey() { Random random = new Random(System.currentTimeMillis()); byte[] key = new byte[16]; random.nextBytes(key); return new String(Base64.encodeBase64(key)); }
From source file:org.apache.wink.itest.standard.JAXRSInputStreamTest.java
/** * Tests a resource method invoked with a ByteArrayInputStream as a * parameter. This should fail with a 415 since the reader has no way to * necessarily wrap it to the type.//ww w . j a v a2 s .co m * * @throws HttpException * @throws IOException */ public void testInputStreamImplementation() throws HttpException, IOException { HttpClient client = new HttpClient(); PostMethod postMethod = new PostMethod( getBaseURI() + "/providers/standard/inputstream/subclasses/shouldfail"); byte[] barr = new byte[100000]; Random r = new Random(); r.nextBytes(barr); postMethod.setRequestEntity(new InputStreamRequestEntity(new ByteArrayInputStream(barr), "any/type")); try { client.executeMethod(postMethod); assertEquals(415, postMethod.getStatusCode()); } finally { postMethod.releaseConnection(); } }
From source file:com.google.nigori.common.DSATest.java
public void generateTestVectors() throws NoSuchAlgorithmException { byte[] privateKey = new byte[NigoriConstants.B_DSA]; Random random = new Random(); for (int i = 0; i < 5; ++i) { random.nextBytes(privateKey); DSASign signer = new DSASign(privateKey); System.out.println("Private key: " + Hex.encodeHexString(privateKey)); System.out.println("Public key: " + Hex.encodeHexString(signer.getPublicKey())); String[] messages = { "message", "", "test", "A message which is longer than a short one and hence might trigger bugs due to long messages which are long long long long................. _* This is a long message *_ .........." }; for (String message : messages) { DSASignature sig = signer.sign(MessageLibrary.toBytes(message)); System.out.println("Message: '" + message + "'"); System.out.println("Signature: r: " + Hex.encodeHexString(sig.getR()) + " s: " + Hex.encodeHexString(sig.getS())); }/*w w w .ja v a2 s .c o m*/ } }
From source file:org.apache.wink.itest.standard.JAXRSSourceTest.java
/** * Tests a resource method invoked with a SAXSource as a parameter. This * should fail with a 415 since the reader has no way to necessarily wrap it * to the type.//from w w w. j av a 2s .c om * * @throws HttpException * @throws IOException */ public void testSourceSubclassImplementation() throws HttpException, IOException { HttpClient client = new HttpClient(); PostMethod postMethod = new PostMethod(getBaseURI() + "/providers/standard/source/subclasses/shouldfail"); byte[] barr = new byte[1000]; Random r = new Random(); r.nextBytes(barr); postMethod .setRequestEntity(new InputStreamRequestEntity(new ByteArrayInputStream(barr), "application/xml")); try { client.executeMethod(postMethod); assertEquals(415, postMethod.getStatusCode()); } finally { postMethod.releaseConnection(); } }
From source file:gobblin.crypto.RotatingAESCodecTest.java
@Test public void testLotsOfData() throws Exception { long bytesToWrite = 20 * 1000 * 1000; byte[] buf = new byte[16384]; long bytesWritten = 0; SimpleCredentialStore credStore = new SimpleCredentialStore(); RotatingAESCodec encryptor = new RotatingAESCodec(credStore); ByteArrayOutputStream sink = new ByteArrayOutputStream(); ByteArrayOutputStream originalBytesStream = new ByteArrayOutputStream(); OutputStream encryptedStream = encryptor.encodeOutputStream(sink); Random r = new Random(); while (bytesWritten < bytesToWrite) { r.nextBytes(buf); originalBytesStream.write(buf);/*from w w w.j a v a 2 s . co m*/ encryptedStream.write(buf); bytesWritten += buf.length; } encryptedStream.close(); byte[] originalBytes = originalBytesStream.toByteArray(); byte[] encryptedBytes = sink.toByteArray(); manuallyDecodeAndVerifyBytes(originalBytes, encryptedBytes, credStore); // Try with stream InputStream decoderIn = encryptor.decodeInputStream(new ByteArrayInputStream(encryptedBytes)); byte[] decoded = IOUtils.toByteArray(decoderIn); Assert.assertEquals(decoded, originalBytes, "Expected decoded output to match encoded output"); }