try (ByteArrayOutputStream bos = new ByteArrayOutputStream(2048)) { IOUtils.copy(src.getInputStream(), bos, 1024); ds = new ByteDataSource(bos.toByteArray(), ct); ds = new ByteDataSource(IOUtils.toString(src.getReader()).getBytes(StandardCharsets.UTF_8), ct); StaxUtils.copy(o, writer); writer.flush(); ds = new ByteDataSource(bwriter.toByteArray(), ct); } catch (XMLStreamException e1) { throw new Fault(e1);
@Override protected Attachment createAttachment(Object object, String id) { byte[] data = (byte[])object; ByteDataSource source = new ByteDataSource(data); source.setContentType(getContentType(object, null)); AttachmentImpl att = new AttachmentImpl(id, new DataHandler(source)); att.setXOP(true); return att; }
@Override protected Attachment createAttachment(Object object, String id) { byte[] data = (byte[])object; ByteDataSource source = new ByteDataSource(data); source.setContentType(getContentType(object, null)); AttachmentImpl att = new AttachmentImpl(id, new DataHandler(source)); att.setXOP(true); return att; }
public static Attachment createMtomAttachment(boolean isXop, String mimeType, String elementNS, byte[] data, int offset, int length, int threshold) { if (!isXop || length <= threshold) { return null; } if (mimeType == null) { mimeType = "application/octet-stream"; } ByteDataSource source = new ByteDataSource(data, offset, length); source.setContentType(mimeType); DataHandler handler = new DataHandler(source); String id; try { id = AttachmentUtil.createContentID(elementNS); } catch (UnsupportedEncodingException e) { throw new Fault(e); } AttachmentImpl att = new AttachmentImpl(id, handler); att.setXOP(isXop); return att; }
ct = "application/octet-stream"; dh = new DataHandler(new ByteDataSource((byte[])o, ct)); } else if (o instanceof String) { if (ct == null) { ct = "text/plain; charset=\'UTF-8\'"; dh = new DataHandler(new ByteDataSource(((String)o).getBytes(StandardCharsets.UTF_8), ct)); } else { throw new Fault(new org.apache.cxf.common.i18n.Message("ATTACHMENT_NOT_SUPPORTED",
public static Attachment createMtomAttachment(boolean isXop, String mimeType, String elementNS, byte[] data, int offset, int length, int threshold) { if (!isXop || length <= threshold) { return null; } if (mimeType == null) { mimeType = "application/octet-stream"; } ByteDataSource source = new ByteDataSource(data, offset, length); source.setContentType(mimeType); DataHandler handler = new DataHandler(source); String id; try { id = AttachmentUtil.createContentID(elementNS); } catch (UnsupportedEncodingException e) { throw new Fault(e); } AttachmentImpl att = new AttachmentImpl(id, handler); att.setXOP(isXop); return att; }
JwsSignatureDataHandler(DataHandler handler) { super(new ByteDataSource("1".getBytes())); this.handler = handler; } @Override
public static Attachment createMtomAttachment(boolean isXop, String mimeType, String elementNS, byte[] data, int offset, int length, int threshold) { if (!isXop || length <= threshold) { return null; } if (mimeType == null) { mimeType = "application/octet-stream"; } ByteDataSource source = new ByteDataSource(data, offset, length); source.setContentType(mimeType); DataHandler handler = new DataHandler(source); String id; try { id = AttachmentUtil.createContentID(elementNS); } catch (UnsupportedEncodingException e) { throw new Fault(e); } AttachmentImpl att = new AttachmentImpl(id, handler); att.setXOP(isXop); return att; }
MessageBodyWriterDataHandler(MessageBodyWriter<T> writer, T obj, Class<T> cls, Type genericType, Annotation[] anns, MediaType contentType) { super(new ByteDataSource("1".getBytes())); this.writer = writer; this.obj = obj; this.cls = cls; this.genericType = genericType; this.anns = anns; this.contentType = contentType; }
public static Attachment createMtomAttachment(boolean isXop, String mimeType, String elementNS, byte[] data, int offset, int length, int threshold) { if (!isXop || length <= threshold) { return null; } if (mimeType == null) { mimeType = "application/octet-stream"; } ByteDataSource source = new ByteDataSource(data, offset, length); source.setContentType(mimeType); DataHandler handler = new DataHandler(source); String id; try { id = AttachmentUtil.createContentID(elementNS); } catch (UnsupportedEncodingException e) { throw new Fault(e); } AttachmentImpl att = new AttachmentImpl(id, handler); att.setXOP(isXop); return att; }
public MessageBodyWriterDataHandler(MessageBodyWriter<T> writer, T obj, Class<T> cls, Type genericType, Annotation[] anns, MediaType contentType) { super(new ByteDataSource("1".getBytes())); this.writer = writer; this.obj = obj; this.cls = cls; this.genericType = genericType; this.anns = anns; this.contentType = contentType; }
return new Attachment(att.getContentId(), dh, att.getHeaders()); } else if (byte[].class.isAssignableFrom(obj.getClass())) { ByteDataSource source = new ByteDataSource((byte[])obj); source.setContentType(mimeType); dh = new DataHandler(source); } else {
/** * Gets the data handler from event. * * @param event the event * @return the data handler */ private static DataHandler getDataHandlerForString(Event event) { try { return new DataHandler(new ByteDataSource(event.getContent().getBytes("UTF-8"))); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
return new Attachment(att.getContentId(), dh, att.getHeaders()); } else if (byte[].class.isAssignableFrom(obj.getClass())) { ByteDataSource source = new ByteDataSource((byte[])obj); source.setContentType(mimeType); dh = new DataHandler(source); } else {
/** * Gets the data handler from event. * * @param event the event * @return the data handler */ private static DataHandler getDataHandlerForString(Event event) { try { return new DataHandler(new ByteDataSource(event.getContent().getBytes("UTF-8"))); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
try (ByteArrayOutputStream bos = new ByteArrayOutputStream(2048)) { IOUtils.copy(src.getInputStream(), bos, 1024); ds = new ByteDataSource(bos.toByteArray(), ct); ds = new ByteDataSource(IOUtils.toString(src.getReader()).getBytes(StandardCharsets.UTF_8), ct); StaxUtils.copy(o, writer); writer.flush(); ds = new ByteDataSource(bwriter.toByteArray(), ct); } catch (XMLStreamException e1) { throw new Fault(e1);
ct = "application/octet-stream"; dh = new DataHandler(new ByteDataSource((byte[])o, ct)); } else if (o instanceof String) { if (ct == null) { ct = "text/plain; charset=\'UTF-8\'"; dh = new DataHandler(new ByteDataSource(((String)o).getBytes(StandardCharsets.UTF_8), ct)); } else { throw new Fault(new org.apache.cxf.common.i18n.Message("ATTACHMENT_NOT_SUPPORTED",