Package freenet.support

Examples of freenet.support.SimpleReadOnlyArrayBucket


        try {
          buf = value.getBytes("UTF-8");
        } catch (UnsupportedEncodingException e) {
          throw new Error("Impossible: JVM doesn't support UTF-8: " + e, e);
        } // FIXME some other encoding?
        RandomAccessBucket b = new SimpleReadOnlyArrayBucket(buf);
        parts.put(parameterValues.getKey(), b);
        if(logMINOR)
          Logger.minor(this, "Added as part: name="+parameterValues.getKey()+" value="+value);
      }
    } else {
View Full Code Here


            COMPRESSOR_TYPE decompressor = COMPRESSOR_TYPE.getCompressorByMetadataID(compressionAlgorithm);
            if (decompressor==null)
              throw new CHKDecodeException("Unknown compression algorithm: "+compressionAlgorithm);
            InputStream inputStream = null;
            OutputStream outputStream = null;
            Bucket inputBucket = new SimpleReadOnlyArrayBucket(input, inputOffset, inputLength-inputOffset);
            Bucket outputBucket = bf.makeBucket(maxLength);
            outputStream = outputBucket.getOutputStream();
            inputStream = inputBucket.getInputStream();
            try {
              decompressor.decompress(inputStream, outputStream, maxLength, -1);
      catch (CompressionOutputSizeException e) {
        throw new TooBigException("Too big");
      } finally {
            inputStream.close();
            outputStream.close();
            inputBucket.free();
      }
            return outputBucket;
        } else {
          return BucketTools.makeImmutableBucket(bf, input, inputLength);
        }
View Full Code Here

  private void charsetTestUnsupported(String charset) throws DataFilterException, IOException, URISyntaxException {
    String original = "@charset \""+charset+"\";\nh2 { color: red;}";
    byte[] bytes = original.getBytes(charset);
    CSSReadFilter filter = new CSSReadFilter();
    SimpleReadOnlyArrayBucket inputBucket = new SimpleReadOnlyArrayBucket(bytes);
    Bucket outputBucket = new ArrayBucket();
    InputStream inputStream = inputBucket.getInputStream();
    OutputStream outputStream = outputBucket.getOutputStream();
    String detectedCharset;
    BOMDetection bom = filter.getCharsetByBOM(bytes, bytes.length);
    String bomCharset = detectedCharset = bom == null ? null : bom.charset;
    assertTrue("Charset detected \""+detectedCharset+"\" should be unknown testing unsupported charset \""+charset+"\" from getCharsetByBOM", detectedCharset == null);
View Full Code Here

  }

  private void testUseMaybeCharset(String charset) throws URISyntaxException, UnsafeContentTypeException, IOException {
    String original = "h2 { color: red;}";
    byte[] bytes = original.getBytes(charset);
    SimpleReadOnlyArrayBucket inputBucket = new SimpleReadOnlyArrayBucket(bytes);
    Bucket outputBucket = new ArrayBucket();
    InputStream inputStream = inputBucket.getInputStream();
    OutputStream outputStream = outputBucket.getOutputStream();
    FilterStatus filterStatus = ContentFilter.filter(inputStream, outputStream, "text/css", new URI("/CHK@OR904t6ylZOwoobMJRmSn7HsPGefHSP7zAjoLyenSPw,x2EzszO4Kqot8akqmKYXJbkD-fSj6noOVGB-K2YisZ4,AAIC--8/1-works.html"), null, null, charset);
    inputStream.close();
    outputStream.close();
    assertEquals(charset, filterStatus.charset);
View Full Code Here

    return new String(buf, "UTF-8");
  }
 
  private ClientCHKBlock encodeBlock(String test, boolean newFormat) throws CHKEncodeException, IOException {
    byte[] data = test.getBytes("UTF-8");
    SimpleReadOnlyArrayBucket bucket = new SimpleReadOnlyArrayBucket(data);
    return ClientCHKBlock.encode(bucket, false, false, (short)-1, bucket.size(), Compressor.DEFAULT_COMPRESSORDESCRIPTOR, false, null, newFormat ? Key.ALGO_AES_CTR_256_SHA256 : Key.ALGO_AES_PCFB_256_SHA256);
  }
View Full Code Here

    return new String(buf, "UTF-8");
  }

  private ClientCHKBlock encodeBlock(String test) throws CHKEncodeException, IOException {
    byte[] data = test.getBytes("UTF-8");
    SimpleReadOnlyArrayBucket bucket = new SimpleReadOnlyArrayBucket(data);
    return ClientCHKBlock.encode(bucket, false, false, (short)-1, bucket.size(), Compressor.DEFAULT_COMPRESSORDESCRIPTOR, false, null, (byte)0);
  }
View Full Code Here

      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

    return new String(buf, "UTF-8");
  }

  private ClientCHKBlock encodeBlockCHK(String test) throws CHKEncodeException, IOException {
    byte[] data = test.getBytes("UTF-8");
    SimpleReadOnlyArrayBucket bucket = new SimpleReadOnlyArrayBucket(data);
    return ClientCHKBlock.encode(bucket, false, false, (short)-1, bucket.size(), Compressor.DEFAULT_COMPRESSORDESCRIPTOR, false, null, (byte)0);
  }
View Full Code Here

    byte[] pkHash = SHA256.digest(pubKey.asBytes());
    String docName = "myDOC";
    InsertableClientSSK ik = new InsertableClientSSK(docName, pkHash, pubKey, privKey, ckey, Key.ALGO_AES_PCFB_256_SHA256);
   
    String test = "test";
    SimpleReadOnlyArrayBucket bucket = new SimpleReadOnlyArrayBucket(test.getBytes("UTF-8"));
    ClientSSKBlock block = ik.encode(bucket, false, false, (short)-1, bucket.size(), random, Compressor.DEFAULT_COMPRESSORDESCRIPTOR, false);
    SSKBlock sskBlock = (SSKBlock) block.getBlock();
    store.put(sskBlock, false, false);
   
    //If the block is the same then there should not be a collision
    try {
      store.put(sskBlock, false, false);
      assertTrue(true);
    } catch (KeyCollisionException e) {
      assertTrue(false);
     
    }
   
    String test1 = "test1";
    SimpleReadOnlyArrayBucket bucket1 = new SimpleReadOnlyArrayBucket(test1.getBytes("UTF-8"));
    ClientSSKBlock block1 = ik.encode(bucket1, false, false, (short)-1, bucket1.size(), random, Compressor.DEFAULT_COMPRESSORDESCRIPTOR, false);
    SSKBlock sskBlock1 = (SSKBlock) block1.getBlock();
   
    //if it's different (e.g. different content, same key), there should be a KCE thrown
    try {
      store.put(sskBlock1, false, false);
View Full Code Here

    return new String(buf, "UTF-8");
  }

  private ClientSSKBlock encodeBlockSSK(String test, RandomSource random) throws IOException, SSKEncodeException, InvalidCompressionCodecException {
    byte[] data = test.getBytes("UTF-8");
    SimpleReadOnlyArrayBucket bucket = new SimpleReadOnlyArrayBucket(data);
    InsertableClientSSK ik = InsertableClientSSK.createRandom(random, test);
    return ik.encode(bucket, false, false, (short)-1, bucket.size(), random, Compressor.DEFAULT_COMPRESSORDESCRIPTOR, false);
  }
View Full Code Here

TOP

Related Classes of freenet.support.SimpleReadOnlyArrayBucket

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.