public DataSourceSource(DataHandler dh) throws MimeTypeParseException { this(dh.getDataSource()); }
/** * Return the data in its preferred Object form. <p> * * If the DataHandler was instantiated with an object, return * the object. <p> * * If the DataHandler was instantiated with a DataSource, * this method uses a DataContentHandler to return the content * object for the data represented by this DataHandler. If no * <code>DataContentHandler</code> can be found for the * the type of this data, the DataHandler returns an * InputStream for the data. * * @return the content. * @exception IOException if an IOException occurs during * this operation. */ public Object getContent() throws IOException { if (object != null) return object; else return getDataContentHandler().getContent(getDataSource()); }
/** * Gets the raw data. The size of the byte array maybe larger than the actual length. */ public byte[] get() { if (data == null) { try { ByteArrayOutputStreamEx baos = new ByteArrayOutputStreamEx(1024); InputStream is = dataHandler.getDataSource().getInputStream(); baos.readFrom(is); is.close(); data = baos.getBuffer(); dataLen = baos.size(); } catch (IOException e) { // TODO: report the error to the unmarshaller dataLen = 0; // recover by assuming length-0 data } } return data; }
public DataSourceSource(DataHandler dh) throws MimeTypeParseException { this(dh.getDataSource()); }
@Override public String addMtomAttachment(DataHandler data, String elementNamespace, String elementLocalName) { return addBinary(data.getDataSource(), data.getContentType()); }
/** * Return the data in its preferred Object form. <p> * * If the DataHandler was instantiated with an object, return * the object. <p> * * If the DataHandler was instantiated with a DataSource, * this method uses a DataContentHandler to return the content * object for the data represented by this DataHandler. If no * <code>DataContentHandler</code> can be found for the * the type of this data, the DataHandler returns an * InputStream for the data. * * @return the content. * @exception IOException if an IOException occurs during * this operation. */ public Object getContent() throws IOException { if (object != null) return object; else return getDataContentHandler().getContent(getDataSource()); }
DataSource dataSource = htmlMimeBodyPart.getDataHandler().getDataSource(); assertEquals(IMAGE_PNG, dataSource.getContentType()); assertArrayEquals(BYTES_1_7, read(dataSource)); dataSource = mimeBodyPart.getDataHandler().getDataSource(); assertEquals(APPLICATION_ZIP, dataSource.getContentType()); assertArrayEquals(BYTES_11_15, read(dataSource));
/** * Gets the raw data. The size of the byte array maybe larger than the actual length. */ public byte[] get() { if (data == null) { try { ByteArrayOutputStreamEx baos = new ByteArrayOutputStreamEx(1024); InputStream is = dataHandler.getDataSource().getInputStream(); baos.readFrom(is); is.close(); data = baos.getBuffer(); dataLen = baos.size(); } catch (IOException e) { // TODO: report the error to the unmarshaller dataLen = 0; // recover by assuming length-0 data } } return data; }
LOGGER.error("Invalid topicId: " + topicId); } else { DataSource dataSource = checkoutResult.getFile().getDataSource(); PluginConfiguration pluginConfiguration = getBimServer().getPluginSettingsCache().getPluginSettings(checkoutResult.getSerializerOid());
public DataHandlerExtImpl(DataHandler dataHandler, LifecycleManager manager){ super(dataHandler.getDataSource()); this.dataHandler = dataHandler; this.manager = manager; }
/** * Parses the MimePart to create a DataSource. * * @param parent the parent multi-part * @param part the current part to be processed * @return the DataSource * @throws MessagingException creating the DataSource failed * @throws IOException creating the DataSource failed */ protected DataSource createDataSource(final Multipart parent, final MimePart part) throws MessagingException, IOException { final DataHandler dataHandler = part.getDataHandler(); final DataSource dataSource = dataHandler.getDataSource(); final String contentType = getBaseMimeType(dataSource.getContentType()); final byte[] content = this.getContent(dataSource.getInputStream()); final ByteArrayDataSource result = new ByteArrayDataSource(content, contentType); final String dataSourceName = getDataSourceName(part, dataSource); result.setName(dataSourceName); return result; }
LOGGER.info("Starting serialization"); DataSource datasource = result.getFile().getDataSource(); if (datasource instanceof ExtendedDataSource) { ((ExtendedDataSource) datasource).writeToOutputStream(baos, null);
if (atts != null) { for (Attachment a : atts) { if (a.getDataHandler().getDataSource() instanceof AttachmentDataSource) { try { ((AttachmentDataSource)a.getDataHandler().getDataSource()).cache(inMessage); } catch (IOException e) { throw new Fault(e);
public DataSource getDataSource() { if (dataSource == null) { dataSource = part.getDataSource(); if (dataSource == null) { // We get here if there is no DataSource implementation specific to the buffering // strategy being used. In this case we use super.getDataSource() to get the // default PartDataSource that we created in the constructor. dataSource = super.getDataSource(); } } return dataSource; }
return getEncoding(dh.getDataSource());
return getEncoding(dh.getDataSource());
private static int getBufferSize(DataHandler dh) { long size = DataSourceUtils.getSize(dh.getDataSource()); if (size == -1) { // Use a reasonable default capacity. return 4096; } else if (size > Integer.MAX_VALUE) { throw new IllegalArgumentException("DataHandler is too large to encode to string"); } else { return getEncodedSize((int)size); } }
@Override public String addMtomAttachment(DataHandler data, String elementNamespace, String elementLocalName) { return addBinary(data.getDataSource(), data.getContentType()); }
public void writeTo(T src, Class<?> cls, Type genericType, Annotation[] annotations, MediaType type, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException { DataSource ds = DataSource.class.isAssignableFrom(cls) ? (DataSource)src : ((DataHandler)src).getDataSource(); if (useDataSourceContentType) { setContentTypeIfNeeded(type, headers, ds.getContentType()); } IOUtils.copyAndCloseInput(ds.getInputStream(), os); }
public void handleMessage(Message message) throws Fault { Assert.assertEquals("check attachment count", 1, message.getAttachments().size()); Attachment att = message.getAttachments().iterator().next(); Assert.assertNotNull("Attachment is null", att); Assert.assertNotNull("Attachment content-type is null", att.getDataHandler().getDataSource() .getContentType()); }