示例#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();
 }
  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());
  }