private void runStreamTest(final int pLength) throws Exception {
    byte[] data = createData(pLength);
    ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
    OutputStream out = new EncoderStream(outBytes, createEncoder(), true);

    try {
      // Provoke failure for encoders that doesn't take array offset properly into account
      int off = (data.length + 1) / 2;
      out.write(data, 0, off);
      if (data.length > off) {
        out.write(data, off, data.length - off);
      }
    } finally {
      out.close();
    }

    byte[] encoded = outBytes.toByteArray();

    //        System.err.println("encoded.length: " + encoded.length);
    //        System.err.println("encoded: " + Arrays.toString(encoded));

    byte[] decoded =
        FileUtil.read(
            new DecoderStream(new ByteArrayInputStream(encoded), createCompatibleDecoder()));
    assertTrue(Arrays.equals(data, decoded));

    InputStream in =
        new DecoderStream(new ByteArrayInputStream(encoded), createCompatibleDecoder());
    outBytes = new ByteArrayOutputStream();

    try {
      FileUtil.copy(in, outBytes);
    } finally {
      outBytes.close();
      in.close();
    }

    decoded = outBytes.toByteArray();
    assertTrue(Arrays.equals(data, decoded));
  }
Ejemplo n.º 2
0
  private static ICC_Profile readProfileFromClasspathResource(final String profilePath) {
    InputStream stream = ColorSpaces.class.getResourceAsStream(profilePath);

    if (stream != null) {
      if (DEBUG) {
        System.out.println("Loading profile from classpath resource: " + profilePath);
      }

      try {

        return ICC_Profile.getInstance(stream);
      } catch (IOException ignore) {
        if (DEBUG) {
          ignore.printStackTrace();
        }
      } finally {
        FileUtil.close(stream);
      }
    }

    return null;
  }