Package freenet.support.math

Examples of freenet.support.math.MersenneTwister.nextBytes()


 
  public void testEncodeDecodeFullBlock() throws CHKEncodeException, CHKVerifyException, CHKDecodeException, UnsupportedEncodingException, InvalidCompressionCodecException, IOException {
    byte[] fullBlock = new byte[CHKBlock.DATA_LENGTH];
    MersenneTwister random = new MersenneTwister(42);
    for(int i=0;i<10;i++) {
      random.nextBytes(fullBlock);
      checkBlock(fullBlock, false);
      checkBlock(fullBlock, true);
    }
  }
 
View Full Code Here


 
  public void testEncodeDecodeRandomLength() throws CHKEncodeException, CHKVerifyException, CHKDecodeException, UnsupportedEncodingException, InvalidCompressionCodecException, IOException
    MersenneTwister random = new MersenneTwister(42);
    for(int i=0;i<10;i++) {
      byte[] buf = new byte[random.nextInt(CHKBlock.DATA_LENGTH+1)];
      random.nextBytes(buf);
      checkBlock(buf, false);
      checkBlock(buf, true);
    }
  }
 
View Full Code Here

 
  public void testEncodeDecodeNearlyFullBlock() throws CHKEncodeException, CHKVerifyException, CHKDecodeException, UnsupportedEncodingException, InvalidCompressionCodecException, IOException
    MersenneTwister random = new MersenneTwister(68);
    for(int i=0;i<10;i++) {
      byte[] buf = new byte[CHKBlock.DATA_LENGTH - i];
      random.nextBytes(buf);
      checkBlock(buf, false);
      checkBlock(buf, true);
    }
    for(int i=0;i<10;i++) {
      byte[] buf = new byte[CHKBlock.DATA_LENGTH - (1<<i)];
View Full Code Here

      checkBlock(buf, false);
      checkBlock(buf, true);
    }
    for(int i=0;i<10;i++) {
      byte[] buf = new byte[CHKBlock.DATA_LENGTH - (1<<i)];
      random.nextBytes(buf);
      checkBlock(buf, false);
      checkBlock(buf, true);
    }
  }
 
View Full Code Here

    EncryptingIoAdapter a = createAdapter();
    MersenneTwister dataMT = new MersenneTwister(seed);
    for(int written=0;written<size;) {
      int write = Math.min(writeStep, size-written);
      byte[] data = new byte[write];
      dataMT.nextBytes(data);
      a.write(data);
      written += write;
    }
    dataMT = new MersenneTwister(seed);
    a.seek(0);
View Full Code Here

    for(int read=0;read<size;) {
      int toRead = Math.min(readStep, size-read);
      int readBytes = a.read(readBuffer, toRead);
      assertTrue(readBytes > 0);
      byte[] compareBuf = new byte[readBytes];
      dataMT.nextBytes(compareBuf);
      for(int i=0;i<compareBuf.length;i++)
        assertTrue("Byte "+(i+read)+" is wrong for buffered test size="+size+" write="+writeStep+" read="+readStep+" seed="+seed, readBuffer[i] == compareBuf[i]);
      read += readBytes;
    }
    a.close();
View Full Code Here

  public void checkLinearBuffered(int size, int writeStep, int readStep, long seed) {
    EncryptingIoAdapter a = createAdapter();
    MersenneTwister dataMT = new MersenneTwister(seed);
    byte[] bigBuffer = new byte[size];
    dataMT.nextBytes(bigBuffer);
    for(int written=0;written<size;) {
      int write = Math.min(writeStep, size-written);
      byte[] data = new byte[write];
      System.arraycopy(bigBuffer,written,data,0,write);
      a.write(data);
View Full Code Here

        System.out.println("Creating test data.");
        File dataFile = File.createTempFile("testdata", ".tmp", dir);
        OutputStream os = new FileOutputStream(dataFile);
        byte[] buf = new byte[4096];
        for(long written = 0; written < TEST_SIZE;) {
          fastRandom.nextBytes(buf);
          int toWrite = (int) Math.min(TEST_SIZE - written, buf.length);
          os.write(buf, 0, toWrite);
          written += toWrite;
        }
        os.close();
View Full Code Here

      BucketTools.copyTo(oldBucket, os, length);
      byte[] buf = new byte[BUFFER_SIZE];
      for(int x=length;x<blockLength;) {
        int remaining = blockLength - x;
        int thisCycle = Math.min(remaining, buf.length);
        mt.nextBytes(buf); // FIXME??
        os.write(buf, 0, thisCycle);
        x += thisCycle;
      }
      os.close();
      os = null;
View Full Code Here

                if(seedRandom != null)
                    mt = new MersenneTwister(seedRandom.nextLong());
                byte[] buf = new byte[4096];
                for(long l = 0; l < forceLength; l+=4096) {
                    if(mt != null)
                        mt.nextBytes(buf);
                    int maxWrite = (int)Math.min(4096, forceLength - l);
                    raf.write(buf, 0, maxWrite);
                }
                assert(raf.getFilePointer() == forceLength);
                assert(raf.length() == forceLength);
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.