Package freenet.support.api

Examples of freenet.support.api.RandomAccessBucket


    this.uploadFrom = uploadFromType;
    this.origFilename = origFilename;
    // Now go through the fields one at a time
    String mimeType = contentType;
    this.clientToken = clientToken;
    RandomAccessBucket tempData = data;
    ClientMetadata cm = new ClientMetadata(mimeType);
    boolean isMetadata = false;
    if(logMINOR) Logger.minor(this, "data = "+tempData+", uploadFrom = "+uploadFrom);
    if(uploadFrom == UploadFrom.REDIRECT) {
      this.targetURI = redirectTarget;
View Full Code Here


    if(mimeType != null && !DefaultMIMETypes.isPlausibleMIMEType(mimeType)) {
      throw new MessageInvalidException(ProtocolErrorMessage.BAD_MIME_TYPE, "Bad MIME type in Metadata.ContentType", identifier, global);
    }
   
    clientToken = message.clientToken;
    RandomAccessBucket tempData = message.getRandomAccessBucket();
    ClientMetadata cm = new ClientMetadata(mimeType);
    boolean isMetadata = false;
    if(logMINOR) Logger.minor(this, "data = "+tempData+", uploadFrom = "+uploadFrom);
    if(uploadFrom == UploadFrom.REDIRECT) {
      this.targetURI = message.redirectTarget;
View Full Code Here

      String identifier, boolean global, BucketFactory bf) throws MessageInvalidException {
    String s = subset.get("DataLength");
    if(s == null)
      throw new MessageInvalidException(ProtocolErrorMessage.MISSING_FIELD, "UploadFrom=direct requires a DataLength for "+name, identifier, global);
    long length;
    RandomAccessBucket data;
    try {
      length = Long.parseLong(s);
    } catch (NumberFormatException e) {
      throw new MessageInvalidException(ProtocolErrorMessage.ERROR_PARSING_NUMBER, "Could not parse DataLength: "+e.toString(), identifier, global);
    }
View Full Code Here

    private File getFile(TempBucket bucket) {
        if(!this.enableCrypto())
            return ((TempFileBucket)(((TempBucket) bucket).getUnderlying())).getFile();
        else {
            EncryptedRandomAccessBucket erab = (EncryptedRandomAccessBucket) bucket.getUnderlying();
            RandomAccessBucket b = erab.getUnderlying();
            if(b instanceof PaddedRandomAccessBucket) {
                b = ((PaddedRandomAccessBucket)b).getUnderlying();
            }
            return ((TempFileBucket) b).getFile();
        }
View Full Code Here

    if(len < 0) return;
    if(len == 0) {
      bucket = new NullBucket();
      return;
    }
    RandomAccessBucket tempBucket;
    try {
      tempBucket = createBucket(bf, len, server);
    } catch (IOException e) {
      Logger.error(this, "Bucket error: "+e, e);
      FileUtil.copy(is, new NullOutputStream(), len);
View Full Code Here

   
    public void testIrregularWrites() throws IOException {
        Random r = new Random(6032405);
        int length = 1024*64+1;
        byte[] data = new byte[length];
        RandomAccessBucket bucket = (RandomAccessBucket) makeBucket(length);
        OutputStream os = bucket.getOutputStream();
        r.nextBytes(data);
        for(int written=0;written<length;) {
            int toWrite = Math.min(length - written, 4095);
            os.write(data, written, toWrite);
            written += toWrite;
        }
        os.close();
        InputStream is = bucket.getInputStream();
        for(int moved=0;moved<length;) {
            int readBytes = Math.min(length - moved, 4095);
            byte[] buf = new byte[readBytes];
            readBytes = is.read(buf);
            assertTrue(readBytes > 0);
            assertTrue(Arrays.equals(Arrays.copyOfRange(buf, 0, readBytes), Arrays.copyOfRange(data, moved, moved+readBytes)));
            moved += readBytes;
        }
        is.close();
        bucket.free();
    }
View Full Code Here

   
    public void testIrregularWritesNotOverlapping() throws IOException {
        Random r = new Random(6032405);
        int length = 1024*64+1;
        byte[] data = new byte[length];
        RandomAccessBucket bucket = (RandomAccessBucket) makeBucket(length);
        OutputStream os = bucket.getOutputStream();
        r.nextBytes(data);
        for(int written=0;written<length;) {
            int toWrite = Math.min(length - written, 4095);
            os.write(data, written, toWrite);
            written += toWrite;
        }
        os.close();
        InputStream is = bucket.getInputStream();
        for(int moved=0;moved<length;) {
            int readBytes = Math.min(length - moved, 4093); // Co-prime with 4095
            byte[] buf = new byte[readBytes];
            readBytes = is.read(buf);
            assertTrue(readBytes > 0);
            assertTrue(Arrays.equals(Arrays.copyOfRange(buf, 0, readBytes), Arrays.copyOfRange(data, moved, moved+readBytes)));
            moved += readBytes;
        }
        is.close();
        bucket.free();
    }
View Full Code Here

   
    public void testBucketToRAF() throws IOException {
        Random r = new Random(6032405);
        int length = 1024*64+1;
        byte[] data = new byte[length];
        RandomAccessBucket bucket = (RandomAccessBucket) makeBucket(length);
        OutputStream os = bucket.getOutputStream();
        r.nextBytes(data);
        for(int written=0;written<length;) {
            int toWrite = Math.min(length - written, 4095);
            os.write(data, written, toWrite);
            written += toWrite;
        }
        os.close();
        InputStream is = bucket.getInputStream();
        for(int moved=0;moved<length;) {
            int readBytes = Math.min(length - moved, 4095);
            byte[] buf = new byte[readBytes];
            readBytes = is.read(buf);
            assertTrue(readBytes > 0);
            assertTrue(Arrays.equals(Arrays.copyOfRange(buf, 0, readBytes), Arrays.copyOfRange(data, moved, moved+readBytes)));
            moved += readBytes;
        }
        LockableRandomAccessBuffer raf = bucket.toRandomAccessBuffer();
        assertEquals(length, raf.size());
        RAFBucket wrapped = new RAFBucket(raf);
        assertTrue(BucketTools.equalBuckets(bucket, wrapped));
        for(int i=0;i<100;i++) {
            int end = length == 1 ? 1 : r.nextInt(length)+1;
View Full Code Here

      System.out.println("SEED-TIME:" + (t2 - t1));
      csvLine.add(String.valueOf(t2 - t1));

      // PUSH N+1 BLOCKS
      for (int i = 0; i <= MAX_N; i++) {
          RandomAccessBucket data = randomData(node);
        HighLevelSimpleClient client = node.clientCore.makeClient((short) 0, false, false);
        FreenetURI uri = new FreenetURI("KSK@" + uid + "-" + dateFormat.format(today.getTime()) + "-" + i);
        System.out.println("PUSHING " + uri);
        client.addEventHook(new ClientEventListener() {

          @Override
          public void receive(ClientEvent ce, ClientContext context) {
            System.out.println(ce.getDescription());
          }
         
        });

        try {
          InsertBlock block = new InsertBlock(data, new ClientMetadata(), uri);
          t1 = System.currentTimeMillis();
          client.insert(block, false, null);
          t2 = System.currentTimeMillis();

          System.out.println("PUSH-TIME-" + i + ":" + (t2 - t1));
          csvLine.add(String.valueOf(t2 - t1));
        } catch (InsertException e) {
          e.printStackTrace();
          csvLine.add("N/A");
        }

        data.free();
      }

      node.park();

      // Node 2
View Full Code Here

    final String[] pullFailures;
  }
 

  private static RandomAccessBucket randomData(Node node) throws IOException {
      RandomAccessBucket data = node.clientCore.tempBucketFactory.makeBucket(TEST_SIZE);
    OutputStream os = data.getOutputStream();
    try {
    byte[] buf = new byte[4096];
    for (long written = 0; written < TEST_SIZE;) {
      node.fastWeakRandom.nextBytes(buf);
      int toWrite = (int) Math.min(TEST_SIZE - written, buf.length);
View Full Code Here

TOP

Related Classes of freenet.support.api.RandomAccessBucket

Copyright © 2018 www.massapicom. 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.