Package freenet.support.io

Examples of freenet.support.io.ArrayBucket


    System.arraycopy(bufUTF16, 0, total, utf16bom.length+buf.length, bufUTF16.length);
    HTMLFilter filter = new HTMLFilter();
    boolean failed = false;
    FileOutputStream fos;
    try {
      ArrayBucket out = new ArrayBucket();
      filter.readFilter(new ArrayBucket(total).getInputStream(), out.getOutputStream(), "UTF-16", null, null);
      fos = new FileOutputStream("output.utf16");
      fos.write(out.toByteArray());
      fos.close();
      failed = true;
      assertFalse("Filter accepted dangerous UTF8 text with BOM as UTF16! (HTMLFilter)", true);
    } catch (DataFilterException e) {
      System.out.println("Failure: "+e);
      e.printStackTrace();
      if(e.getCause() != null) {
        e.getCause().printStackTrace();
      }
      // Ok.
    }
    try {
      ArrayBucket out = new ArrayBucket();
      FilterStatus fo = ContentFilter.filter(new ArrayBucket(total).getInputStream(), out.getOutputStream(), "text/html", null, null);
      fos = new FileOutputStream("output.filtered");
      fos.write(out.toByteArray());
      fos.close();
      failed = true;
      assertFalse("Filter accepted dangerous UTF8 text with BOM as UTF16! (ContentFilter) - Detected charset: "+fo.charset, true);
    } catch (DataFilterException e) {
      System.out.println("Failure: "+e);
View Full Code Here


  public static String HTMLFilter(String data, boolean alt) throws Exception {
    String returnValue;
    String typeName = "text/html";
    URI baseURI = new URI(alt ? ALT_BASE_URI : BASE_URI);
    byte[] dataToFilter = data.getBytes("UTF-8");
    ArrayBucket input = new ArrayBucket(dataToFilter);
    ArrayBucket output = new ArrayBucket();
    InputStream inputStream = input.getInputStream();
    OutputStream outputStream = output.getOutputStream();
    ContentFilter.filter(inputStream, outputStream, typeName, baseURI, null, null, null);
    inputStream.close();
    outputStream.close();
    returnValue = output.toString();
    output.free();
    input.free();
    return returnValue;
  }
View Full Code Here

  }

  protected Bucket resourceToBucket(String filename) throws IOException {
    InputStream is = getClass().getResourceAsStream(filename);
    if (is == null) throw new java.io.FileNotFoundException();
    ArrayBucket ab = new ArrayBucket();
    BucketTools.copyFrom(ab, is, Long.MAX_VALUE);
    return ab;
  }
View Full Code Here

  private void getCharsetTest(String charset, String family) throws DataFilterException, IOException, URISyntaxException {
    String original = "@charset \""+charset+"\";\nh2 { color: red;}";
    byte[] bytes = original.getBytes(charset);
    CSSReadFilter filter = new CSSReadFilter();
    ArrayBucket inputBucket = new ArrayBucket(bytes);
    ArrayBucket outputBucket = new ArrayBucket();
    InputStream inputStream = inputBucket.getInputStream();
    OutputStream outputStream = outputBucket.getOutputStream();
    // Detect with original charset.
    String detectedCharset = filter.getCharset(bytes, bytes.length, charset);
    assertTrue("Charset detected \""+detectedCharset+"\" should be \""+charset+"\" even when parsing with correct charset", charset.equalsIgnoreCase(detectedCharset));
    BOMDetection bom = filter.getCharsetByBOM(bytes, bytes.length);
    String bomCharset = detectedCharset = bom == null ? null : bom.charset;
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);
    detectedCharset = ContentFilter.detectCharset(bytes, bytes.length, cssMIMEType, 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);
    assertEquals("text/css", filterStatus.mimeType);
View Full Code Here

     * @throws CHKDecodeException
     */
  @Override
  public byte[] memoryDecode() throws CHKDecodeException {
    try {
      ArrayBucket a = (ArrayBucket) decode(new ArrayBucketFactory(), 32*1024, false);
      return BucketTools.toByteArray(a); // FIXME
    } catch (IOException e) {
      throw new Error(e);
    }
  }
View Full Code Here

     * @param compressorDescriptor Should be null, or list of compressors to try.
     * @throws InvalidCompressionCodecException
     */
    static public ClientCHKBlock encode(byte[] sourceData, boolean asMetadata, boolean dontCompress, short alreadyCompressedCodec, int sourceLength, String compressorDescriptor, boolean pre1254) throws CHKEncodeException, InvalidCompressionCodecException {
      try {
      return encode(new ArrayBucket(sourceData), asMetadata, dontCompress, alreadyCompressedCodec, sourceLength, compressorDescriptor, pre1254, null, Key.ALGO_AES_CTR_256_SHA256);
    } catch (IOException e) {
      // Can't happen
      throw new Error(e);
    }
    }
View Full Code Here

  }

  public void testCompressException() throws IOException {

    byte[] uncompressedData = UNCOMPRESSED_DATA_1.getBytes();
    Bucket inBucket = new ArrayBucket(uncompressedData);
    BucketFactory factory = new ArrayBucketFactory();

    try {
      Compressor.COMPRESSOR_TYPE.BZIP2.compress(inBucket, factory, 32, 32);
    } catch (CompressionOutputSizeException e) {
View Full Code Here

      uncompressedData[i] = 1;
    }

    byte[] compressedData = doCompress(uncompressedData);

    Bucket inBucket = new ArrayBucket(compressedData);
    NullBucket outBucket = new NullBucket();
    InputStream decompressorInput = null;
    OutputStream decompressorOutput = null;

    try {
      decompressorInput = inBucket.getInputStream();
      decompressorOutput = outBucket.getOutputStream();
      Compressor.COMPRESSOR_TYPE.BZIP2.decompress(decompressorInput, decompressorOutput, 4096 + 10, 4096 + 20);
      decompressorInput.close();
      decompressorOutput.close();
    } catch (CompressionOutputSizeException e) {
      // expect this
      return;
    } finally {
      Closer.close(decompressorInput);
      Closer.close(decompressorOutput);
      inBucket.free();
      outBucket.free();
    }
    fail("did not throw expected CompressionOutputSizeException");

  }
View Full Code Here

TOP

Related Classes of freenet.support.io.ArrayBucket

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.