Package freenet.support.api

Examples of freenet.support.api.Bucket


  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

  }

  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

    return outBuf;
  }

  private byte[] doCompress(byte[] uncompressedData) throws IOException {
    Bucket inBucket = new ArrayBucket(uncompressedData);
    BucketFactory factory = new ArrayBucketFactory();
    Bucket outBucket = null;

    outBucket = Compressor.COMPRESSOR_TYPE.BZIP2.compress(inBucket, factory, 32768, 32768);

    InputStream in = null;
    in = outBucket.getInputStream();
    long size = outBucket.size();
    byte[] outBuf = new byte[(int) size];

    in.read(outBuf);

    return outBuf;
View Full Code Here

  public static void main(String arg[]) throws Throwable {
    final File fin = new File("/tmp/test.png");
    final File fout = new File("/tmp/test2.png");
    fout.delete();
    final Bucket inputBucket = new FileBucket(fin, true, false, false, false);
    final Bucket outputBucket = new FileBucket(fout, false, true, false, false);
    InputStream inputStream = null;
    OutputStream outputStream = null;
    try {
      inputStream = inputBucket.getInputStream();
      outputStream = outputBucket.getOutputStream();
      Logger.setupStdoutLogging(LogLevel.MINOR, "");

      ContentFilter.filter(inputStream, outputStream, "image/png",
          new URI("http://127.0.0.1:8888/"), null, null, null);
    } finally {
      Closer.close(inputStream);
      Closer.close(outputStream);
      inputBucket.free();
      outputBucket.free();
    }
  }
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.GZIP.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.GZIP.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

    return outBuf;
  }

  private byte[] doCompress(byte[] uncompressedData) throws IOException {
    Bucket inBucket = new ArrayBucket(uncompressedData);
    BucketFactory factory = new ArrayBucketFactory();
    Bucket outBucket = null;

    outBucket = Compressor.COMPRESSOR_TYPE.GZIP.compress(inBucket, factory, 32768, 32768);

    InputStream in = null;
    in = outBucket.getInputStream();
    long size = outBucket.size();
    byte[] outBuf = new byte[(int) size];

    in.read(outBuf);

    return outBuf;
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.LZMA_NEW.compress(inBucket, factory, 32, 32);
    } catch (CompressionOutputSizeException e) {
View Full Code Here

TOP

Related Classes of freenet.support.api.Bucket

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.