/** Construct with name, format, content type and binary data. * * <p>It tries to construct format and ctype from each other or name. * * @param name the name (usually filename); might be null. * @param format the format; might be null. Example: "html" and "xml" * @param ctype the content type; might be null. Example: "text/html" * and "text/xml;charset=UTF-8". * @param data the binary data; never null */ public AMedia(String name, String format, String ctype, byte[] data) { if (data == null) throw new IllegalArgumentException("data"); _bindata = data; setup(name, format, ctype); } /** Construct with name, format, content type and text data.
/** Construct with name, format, content type and text data. * * <p>It tries to construct format and ctype from each other or name. * * @param name the name (usually filename); might be null. * @param format the format; might be null. * @param ctype the content type; might be null. * @param data the text data; never null */ public AMedia(String name, String format, String ctype, String data) { if (data == null) throw new IllegalArgumentException("data"); _strdata = data; setup(name, format, ctype); } /** Construct with name, format, content type and stream data (binary).
/** Construct with name, format, content type and reader data (textual). * * <p>It tries to construct format and ctype from each other or name. * * @param name the name (usually filename); might be null. * @param format the format; might be null. * @param ctype the content type; might be null. * @param data the string data; never null * If the reader is created dynamically each time {@link #getReaderData} * is called, you shall pass {@link #DYNAMIC_READER} * as the data argument. Then, override {@link #getReaderData} to return * the correct reader. */ public AMedia(String name, String format, String ctype, Reader data) { if (data == null) throw new IllegalArgumentException("data"); _rddata = data; setup(name, format, ctype); } /** Construct with name, format, content type and a file.
/** Construct with name, format, content type and stream data (binary). * * <p>It tries to construct format and ctype from each other or name. * * @param name the name (usually filename); might be null. * @param format the format; might be null. * @param ctype the content type; might be null. * @param data the binary data; never null. * If the input stream is created dynamically each time {@link #getStreamData} * is called, you shall pass {@link #DYNAMIC_STREAM} * as the data argument. Then, override {@link #getStreamData} to return * the correct stream. * Note: the caller of {@link #getStreamData} has to close * the returned input stream. */ public AMedia(String name, String format, String ctype, InputStream data) { if (data == null) throw new IllegalArgumentException("data"); _isdata = data; setup(name, format, ctype); } /** Construct with name, format, content type and reader data (textual).
name = name.substring(j + 1); setup(name, format, ctype);
/** Construct with name, format, content type and a file. * * <p>Unlike others, it uses the so-called repeatable input * stream or reader (depending on charset is null or not) * to represent the file, so the input stream ({@link #getStreamData}) * or the reader ({@link #getReaderData}) will be re-opened * in the next invocation of {@link InputStream#read} * after {@link InputStream#close} is called. * See also {@link RepeatableInputStream} and {@link RepeatableReader}. * * @param name the name (usually filename); might be null. * If null, the file name is used. * @param format the format; might be null. * @param ctype the content type; might be null. * @param file the file; never null. * @param charset the charset. If null, it is assumed to be binary. */ public AMedia(String name, String format, String ctype, File file, String charset) throws java.io.FileNotFoundException { if (file == null) throw new IllegalArgumentException("file"); if (charset == null) _isdata = RepeatableInputStream.getInstance(file); else _rddata = RepeatableReader.getInstance(file, charset); if (name == null) name = file.getName(); setup(name, format, ctype); } /** Construct with a file.