예제 #1
0
 /**
  * Writes this record to a {@link DataOutput} stream. The output may, in some edge cases, be not
  * byte-for-byte identical to what was parsed from a {@link DataInput}. However it has the same
  * meaning and should not lose any information.
  *
  * @param out The output stream to which this record should be appended.
  * @throws IOException
  */
 public void write(DataOutput out) throws IOException {
   header.write(out);
   out.write(CRLF_BYTES);
   out.write(content);
   out.write(CRLF_BYTES);
   out.write(CRLF_BYTES);
 }
예제 #2
0
  public void write(ByteBuffer buf) {
    ByteBuffer dup = buf.duplicate();
    NIOUtils.skip(buf, 8);
    doWrite(buf);

    header.setBodySize(buf.position() - dup.position() - 8);
    Assert.assertEquals(header.headerSize(), 8);
    header.write(dup);
  }
예제 #3
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();
 }
예제 #4
0
  public int write(DataOutputStream ostream) throws IOException {
    preWrite();
    int retVal = 0;

    {
      /** fix dependent sizes for header * */
    }

    {
      /** fix dependent sizes for resources * */
    }
    {
      /** fix dependent sizes for pvData * */
    }

    {
        /** fix dependent sizes for cvCertificates* */
      certificateCount = (short) (cvCertificates.getCount() - (0));
    }

    // write header
    if (header != null) retVal += header.write(ostream);
    // write protocol_version
    ostream.writeByte(protocol_version);
    retVal += 1;
    // write configuration_count_change
    ostream.writeByte(configuration_count_change);
    retVal += 1;
    // write resources
    if (resources != null) retVal += resources.write(ostream);
    // write pvData
    if (pvData != null) retVal += pvData.write(ostream);
    // write certificateCount
    ostream.writeByte(certificateCount);
    retVal += 1;
    // write cvCertificates
    {
      ArrayList<CVCertificate> temp1 = cvCertificates;
      for (int iIdx = 0; iIdx < temp1.getCount(); iIdx++) {
        CVCertificate temp2 = temp1.get(iIdx);
        if (temp2 != null) retVal += temp2.write(ostream);
      }
    }
    postWrite();
    return retVal;
  }
예제 #5
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());
  }
예제 #6
0
파일: EMF.java 프로젝트: aw1621107/hacks
  @Override
  public void setData(byte[] data) throws IOException {
    byte[] compressed = compress(data, 0, data.length);

    NativeHeader nHeader = new NativeHeader(data, 0);

    Header header = new Header();
    header.wmfsize = data.length;
    header.bounds = nHeader.deviceBounds;
    Dimension nDim = nHeader.getSize();
    header.size = new Dimension(Units.toEMU(nDim.getWidth()), Units.toEMU(nDim.getHeight()));
    header.zipsize = compressed.length;

    byte[] checksum = getChecksum(data);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    out.write(checksum);
    if (uidInstanceCount == 2) {
      out.write(checksum);
    }
    header.write(out);
    out.write(compressed);

    setRawData(out.toByteArray());
  }