private static byte[] decodeBase64(CharSequence text) { if (text instanceof Base64Data) { Base64Data base64Data = (Base64Data) text; return base64Data.getExact(); } else { return DatatypeConverterImpl._parseBase64Binary(text.toString()); } }
public Base64Data print(DataHandler v) { Base64Data bd = new Base64Data(); bd.set(v); return bd; } });
/** * Internally this is only used to split a text to a list, * which doesn't happen that much for base64. * So this method should be smaller than faster. */ public CharSequence subSequence(int start, int end) { StringBuilder buf = new StringBuilder(); get(); // fill in the buffer if we haven't done so for (int i = start; i < end; i++) { buf.append(charAt(i)); } return buf; }
public void text( Pcdata value, boolean needsSeparatingWhitespace ) throws IOException, SAXException, XMLStreamException { if(value instanceof Base64Data && !serializer.getInlineBinaryFlag()) { Base64Data b64d = (Base64Data) value; String cid; if(b64d.hasData()) cid = serializer.attachmentMarshaller.addMtomAttachment( b64d.get(),0,b64d.getDataLen(),b64d.getMimeType(),nsUri,localName); else cid = serializer.attachmentMarshaller.addMtomAttachment( b64d.getDataHandler(),nsUri,localName); if(cid!=null) { nsContext.getCurrent().push(); int prefix = nsContext.declareNsUri(WellKnownNamespace.XOP,"xop",false); beginStartTag(prefix,"Include"); attribute(-1,"href",cid); endStartTag(); endTag(prefix,"Include"); nsContext.getCurrent().pop(); return; } } next.text(value, needsSeparatingWhitespace); } }
/** * Gets the number of characters needed to represent * this binary data in the base64 encoding. */ public int length() { // for each 3 bytes you use 4 chars // if the remainder is 1 or 2 there will be 4 more get(); // fill in the buffer if necessary return ((dataLen + 2) / 3) * 4; }
public void set(Base64Data dt,String mimeType) { dt.set(buf,count,mimeType); }
@Override public void text(Pcdata value, boolean needsSeparatingWhitespace) throws IOException { if (needsSeparatingWhitespace) fiout.writeLowLevelText(" "); /* * Check if the CharSequence is from a base64Binary data type */ if (!(value instanceof Base64Data)) { final int len = value.length(); if(len <buf.length) { value.writeTo(buf, 0); fiout.writeLowLevelText(buf, len); } else { fiout.writeLowLevelText(value.toString()); } } else { final Base64Data dataValue = (Base64Data)value; // Write out the octets using the base64 encoding algorithm fiout.writeLowLevelOctets(dataValue.get(), dataValue.getDataLen()); } }
public DataHandler parse(CharSequence text) { if(text instanceof Base64Data) return ((Base64Data)text).getDataHandler(); else return new DataHandler(new ByteArrayDataSource(decodeBase64(text), UnmarshallingContext.getInstance().getXMIMEContentType())); }
/** * Gets the cached instance of {@link Base64Data}. * * @deprecated * {@link Base64Data} is no longer cached, so that * XMLStreamWriterEx impl can retain the data, like JAX-WS does. */ public Base64Data getCachedBase64DataInstance() { return new Base64Data(); }
public String getContentType() { return getMimeType(); }
public Image parse(CharSequence text) throws SAXException { try { InputStream is; if(text instanceof Base64Data) is = ((Base64Data)text).getInputStream(); else is = new ByteArrayInputStream(decodeBase64(text)); // TODO: buffering is inefficient // technically we should check the MIME type here, but // normally images can be content-sniffed. // so the MIME type check will only make us slower and draconian, both of which // JAXB 2.0 isn't interested. try { return ImageIO.read(is); } finally { is.close(); } } catch (IOException e) { UnmarshallingContext.getInstance().handleError(e); return null; } }
public void text( Pcdata value, boolean needsSeparatingWhitespace ) throws IOException, SAXException, XMLStreamException { if(value instanceof Base64Data && !serializer.getInlineBinaryFlag()) { Base64Data b64d = (Base64Data) value; String cid; if(b64d.hasData()) cid = serializer.attachmentMarshaller.addMtomAttachment( b64d.get(),0,b64d.getDataLen(),b64d.getMimeType(),nsUri,localName); else cid = serializer.attachmentMarshaller.addMtomAttachment( b64d.getDataHandler(),nsUri,localName); if(cid!=null) { nsContext.getCurrent().push(); int prefix = nsContext.declareNsUri(WellKnownNamespace.XOP,"xop",false); beginStartTag(prefix,"Include"); attribute(-1,"href",cid); endStartTag(); endTag(prefix,"Include"); nsContext.getCurrent().pop(); return; } } next.text(value, needsSeparatingWhitespace); } }
/** * Gets the byte[] of the exact length. */ public byte[] getExact() { get(); if (dataLen != data.length) { byte[] buf = new byte[dataLen]; System.arraycopy(data, 0, buf, 0, dataLen); data = buf; } return data; }
/** * Fills in the data object by the byte[] of the exact length. * * @param data * this buffer may be owned directly by the unmarshaleld JAXB object. */ public void set(byte[] data, @Nullable String mimeType) { set(data, data.length, mimeType); }
@Override public void text(Pcdata value, boolean needsSeparatingWhitespace) throws IOException { if (needsSeparatingWhitespace) fiout.writeLowLevelText(" "); /* * Check if the CharSequence is from a base64Binary data type */ if (!(value instanceof Base64Data)) { final int len = value.length(); if(len <buf.length) { value.writeTo(buf, 0); fiout.writeLowLevelText(buf, len); } else { fiout.writeLowLevelText(value.toString()); } } else { final Base64Data dataValue = (Base64Data)value; // Write out the octets using the base64 encoding algorithm fiout.writeLowLevelOctets(dataValue.get(), dataValue.getDataLen()); } }
public void text(Pcdata value, boolean needsSeparatingWhitespace) throws XMLStreamException { if(needsSeparatingWhitespace) { out.writeCharacters(" "); } if (!(value instanceof Base64Data)) { out.writeCharacters(value.toString()); } else { Base64Data v = (Base64Data)value; out.writeBinary(v.getDataHandler()); } } }
Base64Data bd = new Base64Data(); imageData.set(bd,mimeType); return bd;
public String getContentType() { return getMimeType(); }
public Image parse(CharSequence text) throws SAXException { try { InputStream is; if(text instanceof Base64Data) is = ((Base64Data)text).getInputStream(); else is = new ByteArrayInputStream(decodeBase64(text)); // TODO: buffering is inefficient // technically we should check the MIME type here, but // normally images can be content-sniffed. // so the MIME type check will only make us slower and draconian, both of which // JAXB 2.0 isn't interested. try { return ImageIO.read(is); } finally { is.close(); } } catch (IOException e) { UnmarshallingContext.getInstance().handleError(e); return null; } }
public void text( Pcdata value, boolean needsSeparatingWhitespace ) throws IOException, SAXException, XMLStreamException { if(value instanceof Base64Data && !serializer.getInlineBinaryFlag()) { Base64Data b64d = (Base64Data) value; String cid; if(b64d.hasData()) cid = serializer.attachmentMarshaller.addMtomAttachment( b64d.get(),0,b64d.getDataLen(),b64d.getMimeType(),nsUri,localName); else cid = serializer.attachmentMarshaller.addMtomAttachment( b64d.getDataHandler(),nsUri,localName); if(cid!=null) { nsContext.getCurrent().push(); int prefix = nsContext.declareNsUri(WellKnownNamespace.XOP,"xop",false); beginStartTag(prefix,"Include"); attribute(-1,"href",cid); endStartTag(); endTag(prefix,"Include"); nsContext.getCurrent().pop(); return; } } next.text(value, needsSeparatingWhitespace); } }