public boolean isContentEqual(Part other) throws Docx4JException { if (!(other instanceof BinaryPart)) return false; ByteBuffer thisBB = getBuffer(); ByteBuffer thatBB = ((BinaryPart)other).getBuffer(); return thisBB.equals(thatBB); // if (m_ContentType != arg.m_ContentType) // return false; // if (m_Image.GetLongLength(0) != arg.m_Image.GetLongLength(0)) // return false; // // // Compare the arrays byte by byte // long length = m_Image.GetLongLength(0); // for (long n = 0; n < length; n++) // if (m_Image[n] != arg.m_Image[n]) // return false; // return true; }
public byte[] getBytes() { ByteBuffer bb = this.getBuffer(); bb.rewind(); byte[] bytes = new byte[bb.limit()]; bb.get(bytes, 0, bytes.length); bb.rewind(); return bytes; }
protected boolean isInternalImage(AbstractWordXmlPicture picture, Relationship relationship, BinaryPart part) throws Docx4JException { //treat external images, that are loaded, as internal images return (part != null) && ((part.getExternalTarget() == null) || (part.getBuffer() != null)); }
/** * Copy the ByteBuffer containing this part's binary data * to an output stream. * * @param out * @throws IOException */ public void writeDataToOutputStream(OutputStream out) throws IOException { ByteBuffer buf = this.getBuffer(); buf.rewind(); // Fix for https://github.com/plutext/docx4j/issues/80 // from http://stackoverflow.com/questions/579600/how-to-put-the-content-of-a-bytebuffer-into-an-outputstream WritableByteChannel channel = Channels.newChannel(out); channel.write(buf); buf.rewind(); }
protected static void shallowCopyContent(Part source, Part destination) throws Docx4JException { if (source instanceof BinaryPart) { ((BinaryPart)destination).setBinaryData(((BinaryPart)source).getBuffer()); } else if (source instanceof JaxbXmlPart) { ((JaxbXmlPart)destination).setJaxbElement(((JaxbXmlPart)source).getJaxbElement()); ((JaxbXmlPart)destination).setJAXBContext(((JaxbXmlPart)source).getJAXBContext()); } else if (source instanceof CustomXmlDataStoragePart) { ((CustomXmlDataStoragePart)destination).setData(((CustomXmlDataStoragePart)source).getData()); } else if (source instanceof XmlPart) { ((XmlPart)destination).setDocument(((XmlPart)source).getDocument()); } else { throw new IllegalArgumentException("Dont know how to handle a part of type " + source.getClass().getName()); } } }
protected static void deepCopyContent(Part source, Part destination) throws Docx4JException { if (source instanceof BinaryPart) { byte[] byteData = new byte[((BinaryPart)source).getBuffer().limit()]; // = remaining() when current pos = 0 ((BinaryPart)source).getBuffer().get(byteData); ((BinaryPart)destination).setBinaryData(ByteBuffer.wrap(byteData));
((BinaryPart)tmpPart).getBuffer() );
public boolean isContentEqual(Part other) throws Docx4JException { if (!(other instanceof BinaryPart)) return false; ByteBuffer thisBB = getBuffer(); ByteBuffer thatBB = ((BinaryPart)other).getBuffer(); return thisBB.equals(thatBB); // if (m_ContentType != arg.m_ContentType) // return false; // if (m_Image.GetLongLength(0) != arg.m_Image.GetLongLength(0)) // return false; // // // Compare the arrays byte by byte // long length = m_Image.GetLongLength(0); // for (long n = 0; n < length; n++) // if (m_Image[n] != arg.m_Image[n]) // return false; // return true; }
public byte[] getBytes() { ByteBuffer bb = this.getBuffer(); bb.rewind(); byte[] bytes = new byte[bb.limit()]; bb.get(bytes, 0, bytes.length); bb.rewind(); return bytes; }
/** * Copy the ByteBuffer containing this part's binary data * to an output stream. * * @param out * @throws IOException */ public void writeDataToOutputStream(OutputStream out) throws IOException { ByteBuffer buf = this.getBuffer(); buf.rewind(); // Fix for https://github.com/plutext/docx4j/issues/80 // from http://stackoverflow.com/questions/579600/how-to-put-the-content-of-a-bytebuffer-into-an-outputstream WritableByteChannel channel = Channels.newChannel(out); channel.write(buf); buf.rewind(); }
protected boolean isInternalImage(AbstractWordXmlPicture picture, Relationship relationship, BinaryPart part) throws Docx4JException { //treat external images, that are loaded, as internal images return (part != null) && ((part.getExternalTarget() == null) || (part.getBuffer() != null)); }
protected static void shallowCopyContent(Part source, Part destination) throws Docx4JException { if (source instanceof BinaryPart) { ((BinaryPart)destination).setBinaryData(((BinaryPart)source).getBuffer()); } else if (source instanceof JaxbXmlPart) { ((JaxbXmlPart)destination).setJaxbElement(((JaxbXmlPart)source).getJaxbElement()); ((JaxbXmlPart)destination).setJAXBContext(((JaxbXmlPart)source).getJAXBContext()); } else if (source instanceof CustomXmlDataStoragePart) { ((CustomXmlDataStoragePart)destination).setData(((CustomXmlDataStoragePart)source).getData()); } else if (source instanceof XmlPart) { ((XmlPart)destination).setDocument(((XmlPart)source).getDocument()); } else { throw new IllegalArgumentException("Dont know how to handle a part of type " + source.getClass().getName()); } } }
protected static void deepCopyContent(Part source, Part destination) throws Docx4JException { if (source instanceof BinaryPart) { byte[] byteData = new byte[((BinaryPart)source).getBuffer().limit()]; // = remaining() when current pos = 0 ((BinaryPart)source).getBuffer().get(byteData); ((BinaryPart)destination).setBinaryData(ByteBuffer.wrap(byteData));
((BinaryPart)tmpPart).getBuffer() );