📄 pdfsound.java
字号:
// $Id: PDFSound.java,v 1.6 2004/05/18 12:56:04 mike Exp $package org.faceless.pdf;import java.util.*;import java.io.*;/** * A PDFSound represents an audio sample in a PDF document. * Valid types of audio sample include: * <ul> * <li>RIFF file (Microsoft Windows <code>.wav</code> file)</li> * <li>AU file (Sun/NeXT format)</li> * <li>AIFF file (Macintosh format)</li> * <li>AIFF-C file (Compressed Macintosh format)</li> * </ul> * Note that although <i>in theory</i> all these sound * formats are allowed in PDF documents, our own tests have * found incomplete support in Acrobat reader for anything * other than WAV audio files. * <p> * Sound is unlikely to work in anything other than Adobes * own Acrobat products on Windows and Macintosh platforms. * Your mileage may vary. * </p> * * @since 1.1 */public class PDFSound extends PeeredObject{ final org.faceless.pdf2.PDFSound sound; Object getPeer() { return sound; } PDFSound(org.faceless.pdf2.PDFSound sound) { this.sound=sound; } /** * Create a new PDFSound from the specified input file. The file may * be a RIFF (.wav), AIFF, AIFF-C or Sun .au audio file (although see * our note in the class header). * @throws IllegalArgumentException if the file format is invalid */ public PDFSound(InputStream in) throws IllegalArgumentException, IOException { sound = new org.faceless.pdf2.PDFSound(in); } /** * Return the number of samples/second this sound is played at. * Common values are 8000, 11025 or 22050 * @since 1.1.12 */ public int getRate() { return sound.getRate(); } /** * Return the type of sound file this sound represents. Values are * either "RIFF" for Microsoft WAV files, "AU" for Sun Audio files, * "AIFF" or "AIFC" for Apple AIFF or AIFF (compressed) files * respectively. If the type of file cannot be recognised, returns * <tt>null</tt> * @since 1.1.12 */ public String getType() { return sound.getType(); } /** * Return the sampled sound file encapsulated by this PDFSound object * @since 1.1.12 */ public byte[] getStream() { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); InputStream in = sound.getStream(); byte[] b = new byte[1024]; int flen; while ((flen=in.read(b))>=0) { out.write(b, 0, flen); } return out.toByteArray(); } catch (IOException e) { throw new Error("IOException writing to byte array: "+e); } } /** * Set the XML metadata associated with this object. See * {@link PDF#setMetaData} for more information. * @param xmldata the XML data to embed into the document, or <tt>null</tt> to clear any existing metadata. No validation is performed on this input. * @since 1.1.12 */ public void setMetaData(String xmldata) { sound.setMetaData(xmldata); } /** * Return any XML metadata associated with this object. See the * {@link PDF#getMetaData} for more information * @return a {@link java.io.Reader} containing the source of the XML or <tt>null</tt> if no metadata is available. * @throws IOException if the metadata can't be extracted * @since 1.1.12 */ public Reader getMetaData() throws IOException { return sound.getMetaData(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -