/** * 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 obj; else throw new UnsupportedFlavorException(df); }
/** Write the object to the output stream. */ public void writeTo(Object obj, String mimeType, OutputStream os) throws IOException { if (dch != null) dch.writeTo(obj, mimeType, os); else if (obj instanceof byte[]) os.write((byte[]) obj); else if (obj instanceof String) { OutputStreamWriter osw = new OutputStreamWriter(os); osw.write((String) obj); osw.flush(); } else throw new UnsupportedDataTypeException("no object DCH for MIME type " + this.mimeType); }
/** * Return the DataFlavors for this <code>DataContentHandler</code>. * * @return the DataFlavors */ public synchronized DataFlavor[] getTransferDataFlavors() { if (transferFlavors == null) { if (dch != null) { transferFlavors = dch.getTransferDataFlavors(); } else { transferFlavors = new DataFlavor[1]; transferFlavors[0] = new ActivationDataFlavor(obj.getClass(), mimeType, mimeType); } } return transferFlavors; }
/** * Return the DataFlavors for this <code>DataContentHandler</code>. * * @return the DataFlavors */ public DataFlavor[] getTransferDataFlavors() { if (transferFlavors == null) { if (dch != null) { // is there a dch? transferFlavors = dch.getTransferDataFlavors(); } else { transferFlavors = new DataFlavor[1]; transferFlavors[0] = new ActivationDataFlavor(ds.getContentType(), ds.getContentType()); } } return transferFlavors; }
/** * Write the data to an <code>OutputStream</code>. * * <p>If the DataHandler was created with a DataSource, writeTo retrieves the InputStream and * copies the bytes from the InputStream to the OutputStream passed in. * * <p>If the DataHandler was created with an object, writeTo retrieves the DataContentHandler for * the object's type. If the DataContentHandler was found, it calls the <code>writeTo</code> * method on the <code>DataContentHandler</code>. * * @param os the OutputStream to write to * @exception IOException if an I/O error occurs */ public void writeTo(OutputStream os) throws IOException { // for the DataSource case if (dataSource != null) { InputStream is = null; byte data[] = new byte[8 * 1024]; int bytes_read; is = dataSource.getInputStream(); try { while ((bytes_read = is.read(data)) > 0) { os.write(data, 0, bytes_read); } } finally { is.close(); is = null; } } else { // for the Object case DataContentHandler dch = getDataContentHandler(); dch.writeTo(object, objectMimeType, os); } }
/** Write the object to the output stream. */ public void writeTo(Object obj, String mimeType, OutputStream os) throws IOException { if (dch != null) dch.writeTo(obj, mimeType, os); else throw new UnsupportedDataTypeException("no DCH for content type " + ds.getContentType()); }
public Object getContent(DataSource ds) throws IOException { if (dch != null) return dch.getContent(ds); else return ds.getInputStream(); }