@Override public InputStream getInputStream() { try { if(charset!=null) return null; if(is==null) is = source.getInputStream(); return is; } catch (IOException e) { // argh throw new RuntimeException(e); } }
@Override public Reader getReader() { try { if(charset==null) return null; if(r==null) r = new InputStreamReader(source.getInputStream(),charset); return r; } catch (IOException e) { // argh throw new RuntimeException(e); } }
/** * Copies data from {@link DataSource} to a new {@link FastByteArrayOutputStream} and returns this. * * @param input {@link DataSource} to copy from. * @return new {@link FastByteArrayOutputStream} with data from input. * @see #copyToOutputStream(InputStream) */ public static FastByteArrayOutputStream copyToOutputStream(final DataSource input) throws IOException { return copyToOutputStream(input.getInputStream()); }
/** * Copies data from {@link DataSource} to a new {@link FastCharArrayWriter} and returns this. * * @param input {@link DataSource} to copy from. * @return new {@link FastCharArrayWriter} with data from input. * @see #copy(InputStream) */ public static FastCharArrayWriter copy(final DataSource input) throws IOException { return copy(input.getInputStream()); }
public Object getContent(DataSource ds) throws IOException { if (dch != null) return dch.getContent(ds); else return ds.getInputStream(); }
@Override public void writeTo( final DataSource t, final Class<?> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream) throws IOException { final InputStream in = t.getInputStream(); try { writeTo(in, entityStream); } finally { in.close(); } } }
@Override public void writeTo( final DataSource t, final Class<?> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream) throws IOException { final InputStream in = t.getInputStream(); try { writeTo(in, entityStream); } finally { in.close(); } } }
/** * Return the Transfer Data of type DataFlavor from InputStream. * @param df the DataFlavor * @param ds the DataSource * @return the constructed Object */ public Object getTransferData(DataFlavor df, DataSource ds) throws UnsupportedFlavorException, IOException { if (dch != null) return dch.getTransferData(df, ds); else if (df.equals(getTransferDataFlavors()[0])) // only have one now return ds.getInputStream(); else throw new UnsupportedFlavorException(df); }
private byte[] read(final DataSource dataSource) throws IOException { final ByteArrayOutputStream os = new ByteArrayOutputStream(); StreamUtil.copy(dataSource.getInputStream(), os); return os.toByteArray(); } }
int bytes_read; is = dataSource.getInputStream();
/** * Saves attachment to a file. * * @param destination The destination file to be written. */ public void writeToFile(final File destination) { InputStream input = null; final OutputStream output; try { input = getDataSource().getInputStream(); output = new FileOutputStream(destination); StreamUtil.copy(input, output); } catch (final IOException ioex) { throw new MailException(ioex); } finally { StreamUtil.close(input); } }
/** * Creates {@link EmailAttachment}. * * @return {@link EmailAttachment}. * @throws MailException if issue with {@link DataSource}. */ public EmailAttachment<FileDataSource> buildFileDataSource(final String messageId, final File attachmentStorage) throws MailException { try { final FileDataSource fds; if (dataSource instanceof FileDataSource) { fds = (FileDataSource) dataSource; } else { final File file = new File(attachmentStorage, messageId); FileUtil.writeStream(file, dataSource.getInputStream()); fds = new FileDataSource(file); } checkDataSource(); return new EmailAttachment<>(name, contentId, isInline, fds).setEmbeddedMessage(targetMessage); } catch (final IOException ioexc) { throw new MailException(ioexc); } }
/** * Saves attachment to the output stream. * * @param out OutputStream where attachment should be copied to. */ public void writeToStream(final OutputStream out) { InputStream input = null; try { input = getDataSource().getInputStream(); StreamUtil.copy(input, out); } catch (final IOException ioex) { throw new MailException(ioex); } finally { StreamUtil.close(input); } }
/** * 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; }
ins = dataSource.getInputStream(); } else { DataContentHandler dch = getDataContentHandler();
/** * Creates {@link EmailAttachment}. * * @return {@link EmailAttachment}. * @throws MailException if issue with {@link DataSource}. */ public EmailAttachment<ByteArrayDataSource> buildByteArrayDataSource() throws MailException { try { final ByteArrayDataSource bads; if (dataSource instanceof ByteArrayDataSource) { bads = (ByteArrayDataSource) dataSource; } else { bads = new ByteArrayDataSource(dataSource.getInputStream(), dataSource.getContentType()); } checkDataSource(); return new EmailAttachment<>(name, contentId, isInline, bads).setEmbeddedMessage(targetMessage); } catch (final IOException ioexc) { throw new MailException(ioexc); } }
@Override public InputStream getInputStream() { try { if(charset!=null) return null; if(is==null) is = source.getInputStream(); return is; } catch (IOException e) { // argh throw new RuntimeException(e); } }
public Object getContent(DataSource ds) throws IOException { if (dch != null) return dch.getContent(ds); else return ds.getInputStream(); }
protected Object getData(ActivationDataFlavor aFlavor, DataSource ds) throws IOException { if (aFlavor.getRepresentationClass() == String.class) return super.getContent(ds); else if (aFlavor.getRepresentationClass() == StreamSource.class) return new StreamSource(ds.getInputStream()); else return null; // XXX - should never happen }
@Override protected Object getData(ActivationDataFlavor aFlavor, DataSource ds) throws IOException { if (aFlavor.getRepresentationClass() == String.class) return super.getContent(ds); else if (aFlavor.getRepresentationClass() == StreamSource.class) return new StreamSource(ds.getInputStream()); else return null; // XXX - should never happen }