Package freenet.client

Examples of freenet.client.InsertBlock


          RandomAccessBucket data = randomData(node);
        HighLevelSimpleClient client = node.clientCore.makeClient((short) 0, false, false);
        System.out.println("PUSHING " + i);

        try {
          InsertBlock block = new InsertBlock(data, new ClientMetadata(), FreenetURI.EMPTY_CHK_URI);
          t1 = System.currentTimeMillis();
          FreenetURI uri = client.insert(block, false, null);
          if(i == 0) todaysInsert = uri;
          t2 = System.currentTimeMillis();
View Full Code Here


        if(!cancel) {
          if(!binaryBlob) {
            ClientMetadata meta = cm;
            if(meta != null) meta = persistent() ? meta.clone() : meta;
            currentState =
              new SingleFileInserter(this, this, new InsertBlock(data, meta, targetURI), isMetadata, ctx, realTimeFlag,
                  false, false, null, null, false, targetFilename, false, persistent(), 0, 0, null, cryptoAlgorithm, cryptoKey, metadataThreshold);
          } else
            currentState =
              new BinaryBlobInserter(data, this, getClient(), false, priorityClass, ctx, context);
        }
View Full Code Here

                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",
View Full Code Here

                content = readLines(reader, false);
            }
            // Insert
            byte[] data = content.getBytes(ENCODING);
           
            InsertBlock block = new InsertBlock(new ArrayBucket(data), null, FreenetURI.EMPTY_CHK_URI);

            FreenetURI uri;
            try {
              uri = client.insert(block, getCHKOnly, null);
            } catch (InsertException e) {
                outsb.append("Error: ").append(e.getMessage());
              if(e.uri != null)
                    outsb.append("URI would have been: ").append(e.uri);
              InsertExceptionMode mode = e.getMode();
              if((mode == InsertExceptionMode.FATAL_ERRORS_IN_BLOCKS) || (mode == InsertExceptionMode.TOO_MANY_RETRIES_IN_BLOCKS)) {
                    outsb.append("Splitfile-specific error:\n").append(e.errorCodes.toVerboseString());
              }
    outsb.append("\r\n");
    w.write(outsb.toString());
    w.flush();
              return false;
            }

            outsb.append("URI: ").append(uri);
            ////////////////////////////////////////////////////////////////////////////////
        } else if(uline.startsWith("PUTDIR:") || (uline.startsWith("PUTSSKDIR")) || (getCHKOnly = uline.startsWith("GETCHKDIR:"))) {
          // TODO: Check for errors?
          boolean ssk = false;
          if(uline.startsWith("PUTDIR:"))
            line = line.substring("PUTDIR:".length());
          else if(uline.startsWith("PUTSSKDIR:")) {
            line = line.substring("PUTSSKDIR:".length());
            ssk = true;
          } else if(uline.startsWith("GETCHKDIR:"))
            line = line.substring(("GETCHKDIR:").length());
          else {
            System.err.println("Impossible");
            outsb.append("Impossible");
          }
         
          line = line.trim();
         
          if(line.length() < 1) {
            printHeader(w);
      outsb.append("\r\n");
      w.write(outsb.toString());
      w.flush();
            return false;
          }
         
          String defaultFile = null;
         
          FreenetURI insertURI = FreenetURI.EMPTY_CHK_URI;
         
          // set default file?
          if (line.matches("^.*#.*$")) {
            String[] split = line.split("#");
            if(ssk) {
              insertURI = new FreenetURI(split[0]);
              line = split[1];
              if(split.length > 2)
                defaultFile = split[2];
            } else {
              defaultFile = split[1];
              line = split[0];
            }
          }
         
          HashMap<String, Object> bucketsByName =
            makeBucketsByName(line);
         
          if(defaultFile == null) {
            String[] defaultFiles =
              new String[] { "index.html", "index.htm", "default.html", "default.htm" };
            for(String file: defaultFiles) {
              if(bucketsByName.containsKey(file)) {
                defaultFile = file;
                break;
              }               
            }
          }
         
          FreenetURI uri;
      try {
        uri = client.insertManifest(insertURI, bucketsByName, defaultFile);
        uri = uri.addMetaStrings(new String[] { "" });
            outsb.append("=======================================================");
                outsb.append("URI: ").append(uri);
            outsb.append("=======================================================");
      } catch (InsertException e) {
                outsb.append("Finished insert but: ").append(e.getMessage());
              if(e.uri != null) {
                uri = e.uri;
            uri = uri.addMetaStrings(new String[] { "" });
                    outsb.append("URI would have been: ").append(uri);
              }
              if(e.errorCodes != null) {
                outsb.append("Splitfile errors breakdown:");
                outsb.append(e.errorCodes.toVerboseString());
              }
              Logger.error(this, "Caught "+e, e);
      }
           
        } else if(uline.startsWith("PUTFILE:") || (getCHKOnly = uline.startsWith("GETCHKFILE:"))) {
            // Just insert to local store
          if(getCHKOnly) {
            line = line.substring(("GETCHKFILE:").length()).trim();
          } else {
            line = line.substring("PUTFILE:".length()).trim();
          }
            String mimeType = DefaultMIMETypes.guessMIMEType(line, false);
            if (line.indexOf('#') > -1) {
              String[] splittedLine = line.split("#");
              line = splittedLine[0];
              mimeType = splittedLine[1];
            }
            File f = new File(line);
            outsb.append("Attempting to read file ").append(line);
            long startTime = System.currentTimeMillis();
            try {
              if(!(f.exists() && f.canRead())) {
                throw new FileNotFoundException();
              }
             
              // Guess MIME type
                outsb.append(" using MIME type: ").append(mimeType).append("\r\n");
              if(mimeType.equals(DefaultMIMETypes.DEFAULT_MIME_TYPE))
                mimeType = ""; // don't need to override it
             
              FileBucket fb = new FileBucket(f, true, false, false, false);
              InsertBlock block = new InsertBlock(fb, new ClientMetadata(mimeType), FreenetURI.EMPTY_CHK_URI);

              startTime = System.currentTimeMillis();
              FreenetURI uri = client.insert(block, getCHKOnly, f.getName());
             
              // FIXME depends on CHK's still being renamable
View Full Code Here

    InsertableClientSSK key = InsertableClientSSK.createRandom(node.random, "");
    FreenetURI targetUri = key.getInsertURI().setDocName(filenameHint);
    InsertContext insertContext = client.getInsertContext(true);
    Bucket bucket = new ArrayBucket(temporaryImage.getImageData());
    ClientMetadata metadata = new ClientMetadata(temporaryImage.getMimeType());
    InsertBlock insertBlock = new InsertBlock(bucket, metadata, targetUri);
    try {
      ClientPutter clientPutter = client.insert(insertBlock, false, null, false, insertContext, insertToken, RequestStarter.INTERACTIVE_PRIORITY_CLASS);
      insertToken.setClientPutter(clientPutter);
    } catch (InsertException ie1) {
      throw new SoneInsertException("Could not start image insert.", ie1);
View Full Code Here

      mXML.encode(m, os);
      os.close(); os = null;
      tempB.setReadOnly();

      /* We do not specifiy a ClientMetaData with mimetype because that would result in the insertion of an additional CHK */
      InsertBlock ib = new InsertBlock(tempB, null, m.getInsertURI());
      InsertContext ictx = mClient.getInsertContext(true);

      ClientPutter pu = mClient.insert(ib, false, null, false, ictx, this, RequestStarter.INTERACTIVE_PRIORITY_CLASS);
      addInsert(pu);
      mPutterMessageIDs.put(pu, m.getID());
View Full Code Here

      mXML.encode(mMessageManager, list, os);
      os.close(); os = null;
      tempB.setReadOnly();

      /* We do not specifiy a ClientMetaData with mimetype because that would result in the insertion of an additional CHK */
      InsertBlock ib = new InsertBlock(tempB, null, list.getInsertURI());
      InsertContext ictx = mClient.getInsertContext(true);

      ClientPutter pu = mClient.insert(ib, false, null, false, ictx, this, RequestStarter.INTERACTIVE_PRIORITY_CLASS);
      addInsert(pu);
      tempB = null;
View Full Code Here

TOP

Related Classes of freenet.client.InsertBlock

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.