Examples of RandomAccessBucket


Examples of freenet.support.api.RandomAccessBucket

            if (type == null) {
                type = "text/plain";
            }
            ClientMetadata contentType = new ClientMetadata(type);

            RandomAccessBucket bucket = request.getPart("filename");

            PageNode page = ctx.getPageMaker().getPageNode(l10n("insertedTitle"), ctx);
            HTMLNode pageNode = page.outer;
            HTMLNode contentNode = page.content;
            HTMLNode content;
            String filenameHint = null;
            if (key.getKeyType().equals("CHK")) {
                String[] metas = key.getAllMetaStrings();
                if ((metas != null) && (metas.length > 1)) {
                    filenameHint = metas[0];
                }
            }
            InsertBlock block = new InsertBlock(bucket, contentType, key);
            try {
                key = this.insert(block, filenameHint, false);
                content = ctx.getPageMaker().getInfobox("infobox-success", l10n("insertSucceededTitle"), contentNode, "successful-insert", false);
                String u = key.toString();
                NodeL10n.getBase().addL10nSubstitution(content, "WelcomeToadlet.keyInsertedSuccessfullyWithKeyAndName",
                        new String[]{"link", "name"},
                        new HTMLNode[] { HTMLNode.link("/"+u), HTMLNode.text(u) });
            } catch (InsertException e) {
              content = ctx.getPageMaker().getInfobox("infobox-error", l10n("insertFailedTitle"), contentNode, "failed-insert", false);
                content.addChild("#", l10n("insertFailedWithMessage", "message", e.getMessage()));
                content.addChild("br");
                if (e.uri != null) {
                    content.addChild("#", l10n("uriWouldHaveBeen", "uri", e.uri.toString()));
                }
                InsertExceptionMode mode = e.getMode();
                if ((mode == InsertExceptionMode.FATAL_ERRORS_IN_BLOCKS) || (mode == InsertExceptionMode.TOO_MANY_RETRIES_IN_BLOCKS)) {
                    content.addChild("br"); /* TODO */
                    content.addChild("#", l10n("splitfileErrorLabel"));
                    content.addChild("pre", e.errorCodes.toVerboseString());
                }
            }

            content.addChild("br");
            addHomepageLink(content);

            writeHTMLReply(ctx, 200, "OK", pageNode.generate());
            request.freeParts();
            bucket.free();
        } else if (request.isPartSet("exit")) {
          PageNode page = ctx.getPageMaker().getPageNode(l10n("shutdownConfirmTitle"), ctx);
            HTMLNode pageNode = page.outer;
            HTMLNode contentNode = page.content;
            HTMLNode content = ctx.getPageMaker().getInfobox("infobox-query", l10n("shutdownConfirmTitle"), contentNode, "shutdown-confirm", true);
View Full Code Here

Examples of freenet.support.api.RandomAccessBucket

  public static RandomAccessBucket makeImmutableBucket(BucketFactory bucketFactory, byte[] data, int length) throws IOException {
    return makeImmutableBucket(bucketFactory, data, 0, length);
  }
 
  public static RandomAccessBucket makeImmutableBucket(BucketFactory bucketFactory, byte[] data, int offset, int length) throws IOException {
    RandomAccessBucket bucket = bucketFactory.makeBucket(length);
    OutputStream os = bucket.getOutputStreamUnbuffered();
    try {
    os.write(data, offset, length);
    } finally {
    os.close();
    }
    bucket.setReadOnly();
    return bucket;
  }
View Full Code Here

Examples of freenet.support.api.RandomAccessBucket

   
    public static RandomAccessBucket toRandomAccessBucket(Bucket bucket, BucketFactory bf) throws IOException {
        if(bucket instanceof RandomAccessBucket)
            return (RandomAccessBucket)bucket;
        if(bucket instanceof DelayedFreeBucket) {
            RandomAccessBucket ret = ((DelayedFreeBucket)bucket).toRandomAccessBucket();
            if(ret != null) return ret;
        }
        RandomAccessBucket ret = bf.makeBucket(bucket.size());
        BucketTools.copy(bucket, ret);
        bucket.free();
        return ret;
    }
View Full Code Here

Examples of freenet.support.api.RandomAccessBucket

  }

  @Override
  public FreenetURI insertRedirect(FreenetURI insertURI, FreenetURI targetURI) throws InsertException {
    Metadata m = new Metadata(DocumentType.SIMPLE_REDIRECT, null, null, targetURI, new ClientMetadata());
    RandomAccessBucket b;
    try {
      b = m.toBucket(bucketFactory);
    } catch (IOException e) {
      Logger.error(this, "Bucket error: "+e, e);
      throw new InsertException(InsertExceptionMode.INTERNAL_ERROR, e, null);
View Full Code Here

Examples of freenet.support.api.RandomAccessBucket

   * @exception IOException
   *                If it is not possible to create a temp bucket due to an
   *                I/O error
   */
  public TempBucket makeBucket(long size, float factor, long increment) throws IOException {
    RandomAccessBucket realBucket = null;
    boolean useRAMBucket = false;
    long now = System.currentTimeMillis();
   
    synchronized(this) {
      if((size > 0) && (size <= maxRAMBucketSize) && (bytesInUse < maxRamUsed) && (bytesInUse + size <= maxRamUsed)) {
View Full Code Here

Examples of freenet.support.api.RandomAccessBucket

  }
 
  private final Queue<WeakReference<Migratable>> ramBucketQueue = new LinkedBlockingQueue<WeakReference<Migratable>>();
 
  private RandomAccessBucket _makeFileBucket() throws IOException {
    RandomAccessBucket ret = new TempFileBucket(filenameGenerator.makeRandomFilename(), filenameGenerator, true);
    // Do we want it to be encrypted?
    if(reallyEncrypt) {
            ret = new PaddedRandomAccessBucket(ret);
        ret = new EncryptedRandomAccessBucket(CRYPT_TYPE, ret, secret);
    }
View Full Code Here

Examples of freenet.support.api.RandomAccessBucket

      synchronized(this) {
        if(!isRAMBucket() || hasBeenFreed)
          // Nothing to migrate! We don't want to switch back to ram, do we?         
          return false;
        toMigrate = currentBucket;
        RandomAccessBucket tempFB = _makeFileBucket();
        size = currentSize;
        if(os != null) {
          os.flush();
          os.close();
          // DO NOT INCREMENT THE osIndex HERE!
          os = tempFB.getOutputStreamUnbuffered();
          if(size > 0)
            BucketTools.copyTo(toMigrate, os, size);
        } else {
          if(size > 0) {
            OutputStream temp = tempFB.getOutputStreamUnbuffered();
            try {
            BucketTools.copyTo(toMigrate, temp, size);
            } finally {
            temp.close();
            }
          }
        }
        if(toMigrate.isReadOnly())
          tempFB.setReadOnly();
       
        closeInputStreams(false);
       
        currentBucket = tempFB;
        // We need streams to be reset to point to the new bucket
View Full Code Here

Examples of freenet.support.api.RandomAccessBucket

      buf = s.getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
      throw new Error("Impossible: JVM doesn't support UTF-8: " + e, e);
    }
   
    RandomAccessBucket b = new SimpleReadOnlyArrayBucket(buf);
   
    long number = crypto.myARKNumber;
    InsertableClientSSK ark = crypto.myARK;
    FreenetURI uri = ark.getInsertURI().setKeyType("USK").setSuggestedEdition(number);
   
View Full Code Here

Examples of freenet.support.api.RandomAccessBucket

  public void resolve(String name) {
    this.resolvedName = name;
  }

  public RandomAccessBucket toBucket(BucketFactory bf) throws MetadataUnresolvedException, IOException {
      RandomAccessBucket b = bf.makeBucket(-1);
      DataOutputStream dos = null;
      boolean success = false;
      try {
          dos = new DataOutputStream(b.getOutputStream());
          writeTo(dos);
          dos.close();
          dos = null;
          b.setReadOnly(); // Must be after dos.close()
          success = true;
          return b;
      } finally {
          Closer.close(dos);
          if(!success) b.free();
      }
  }
View Full Code Here

Examples of freenet.support.api.RandomAccessBucket

  /** Create a persistent temporary bucket. Encrypted if appropriate. Wrapped in a
   * DelayedFreeBucket so that they will not be deleted until after the transaction deleting
   * them in the database commits. */
  @Override
  public RandomAccessBucket makeBucket(long size) throws IOException {
    RandomAccessBucket rawBucket = null;
    boolean mustWrap = true;
    if(rawBucket == null)
      rawBucket = new PersistentTempFileBucket(fg.makeRandomFilename(), fg, this);
    synchronized(encryptLock) {
        if(encrypt) {
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.