Ejemplo n.º 1
0
 public void write(FileOutputStream fos) throws IOException {
   FileChannel chan = fos.getChannel();
   // Create ByteBuffer for header in case the start of our
   // ByteBuffer isn't actually memory-mapped
   ByteBuffer hdr = ByteBuffer.allocate(Header.writtenSize());
   hdr.order(ByteOrder.LITTLE_ENDIAN);
   header.write(hdr);
   hdr.rewind();
   chan.write(hdr);
   buf.position(Header.writtenSize());
   chan.write(buf);
   chan.force(true);
   chan.close();
 }
Ejemplo n.º 2
0
  public void setData(byte[] data) throws IOException {
    int pos = 512; // skip the first 512 bytes - they are MAC specific crap
    byte[] compressed = compress(data, pos, data.length - pos);

    Header header = new Header();
    header.wmfsize = data.length - 512;
    // we don't have a PICT reader in java, have to set default image size  200x200
    header.bounds = new java.awt.Rectangle(0, 0, 200, 200);
    header.size =
        new java.awt.Dimension(
            header.bounds.width * Shape.EMU_PER_POINT, header.bounds.height * Shape.EMU_PER_POINT);
    header.zipsize = compressed.length;

    byte[] checksum = getChecksum(data);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    out.write(checksum);

    out.write(new byte[16]); // 16-byte prefix which is safe to ignore
    header.write(out);
    out.write(compressed);

    setRawData(out.toByteArray());
  }