Mercurial > jmeCapture
view src/ca/randelshofer/ImageOutputStreamAdapter.java @ 18:2543c95a0fd2
fixed sound problem
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 29 Oct 2011 14:39:19 -0700 |
parents | 4c5fc53778c1 |
children | 302d5e9ad120 |
line wrap: on
line source
1 /*2 * @(#)ImageOutputStreamAdapter.java 1.1 2011-01-073 *4 * Copyright © 2010 Werner Randelshofer, Immensee, Switzerland.5 * All rights reserved.6 *7 * You may not use, copy or modify this file, except in compliance with the8 * license agreement you entered into with Werner Randelshofer.9 * For details see accompanying license terms.10 */11 package ca.randelshofer;13 import java.io.IOException;14 import java.io.OutputStream;16 import javax.imageio.stream.ImageOutputStream;18 /**19 * Adapts an {@code ImageOutputStream} for classes requiring an20 * {@code OutputStream}.21 *22 * @author Werner Randelshofer23 * @version 1.1 2011-01-07 Fixes performance.24 * <br>1.0 2010-12-26 Created.25 */26 public class ImageOutputStreamAdapter extends OutputStream {28 /**29 * The underlying output stream to be filtered.30 */31 protected ImageOutputStream out;33 /**34 * Creates an output stream filter built on top of the specified35 * underlying output stream.36 *37 * @param out the underlying output stream to be assigned to38 * the field <tt>this.out</tt> for later use, or39 * <code>null</code> if this instance is to be40 * created without an underlying stream.41 */42 public ImageOutputStreamAdapter(ImageOutputStream out) {43 this.out = out;44 }46 /**47 * Writes the specified <code>byte</code> to this output stream.48 * <p>49 * The <code>write</code> method of <code>FilterOutputStream</code>50 * calls the <code>write</code> method of its underlying output stream,51 * that is, it performs <tt>out.write(b)</tt>.52 * <p>53 * Implements the abstract <tt>write</tt> method of <tt>OutputStream</tt>.54 *55 * @param b the <code>byte</code>.56 * @exception IOException if an I/O error occurs.57 */58 @Override59 public void write(int b) throws IOException {60 out.write(b);61 }63 /**64 * Writes <code>b.length</code> bytes to this output stream.65 * <p>66 * The <code>write</code> method of <code>FilterOutputStream</code>67 * calls its <code>write</code> method of three arguments with the68 * arguments <code>b</code>, <code>0</code>, and69 * <code>b.length</code>.70 * <p>71 * Note that this method does not call the one-argument72 * <code>write</code> method of its underlying stream with the single73 * argument <code>b</code>.74 *75 * @param b the data to be written.76 * @exception IOException if an I/O error occurs.77 * @see java.io.FilterOutputStream#write(byte[], int, int)78 */79 @Override80 public void write(byte b[]) throws IOException {81 write(b, 0, b.length);82 }84 /**85 * Writes <code>len</code> bytes from the specified86 * <code>byte</code> array starting at offset <code>off</code> to87 * this output stream.88 * <p>89 * The <code>write</code> method of <code>FilterOutputStream</code>90 * calls the <code>write</code> method of one argument on each91 * <code>byte</code> to output.92 * <p>93 * Note that this method does not call the <code>write</code> method94 * of its underlying input stream with the same arguments. Subclasses95 * of <code>FilterOutputStream</code> should provide a more efficient96 * implementation of this method.97 *98 * @param b the data.99 * @param off the start offset in the data.100 * @param len the number of bytes to write.101 * @exception IOException if an I/O error occurs.102 * @see java.io.FilterOutputStream#write(int)103 */104 @Override105 public void write(byte b[], int off, int len) throws IOException {106 out.write(b,off,len);107 }109 /**110 * Flushes this output stream and forces any buffered output bytes111 * to be written out to the stream.112 * <p>113 * The <code>flush</code> method of <code>FilterOutputStream</code>114 * calls the <code>flush</code> method of its underlying output stream.115 *116 * @exception IOException if an I/O error occurs.117 * @see java.io.FilterOutputStream#out118 */119 @Override120 public void flush() throws IOException {121 out.flush();122 }124 /**125 * Closes this output stream and releases any system resources126 * associated with the stream.127 * <p>128 * The <code>close</code> method of <code>FilterOutputStream</code>129 * calls its <code>flush</code> method, and then calls the130 * <code>close</code> method of its underlying output stream.131 *132 * @exception IOException if an I/O error occurs.133 * @see java.io.FilterOutputStream#flush()134 * @see java.io.FilterOutputStream#out135 */136 @Override137 public void close() throws IOException {138 try {139 flush();140 } finally {141 out.close();142 }143 }144 }