0N/A/*
6321N/A * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage com.sun.media.sound;
0N/A
0N/Aimport java.io.File;
0N/Aimport java.io.InputStream;
0N/Aimport java.io.OutputStream;
0N/Aimport java.io.IOException;
0N/Aimport java.io.DataInputStream;
0N/A
0N/Aimport javax.sound.sampled.AudioFileFormat;
0N/Aimport javax.sound.sampled.AudioInputStream;
0N/Aimport javax.sound.sampled.spi.AudioFileWriter;
0N/A
0N/A
0N/A
0N/A
0N/A/**
0N/A * Abstract File Writer class.
0N/A *
0N/A * @author Jan Borgersen
0N/A */
0N/Aabstract class SunFileWriter extends AudioFileWriter {
0N/A
0N/A
0N/A // buffer size for write
0N/A protected static final int bufferSize = 16384;
0N/A
0N/A // buffer size for temporary input streams
0N/A protected static final int bisBufferSize = 4096;
0N/A
0N/A
0N/A final AudioFileFormat.Type types[];
0N/A
0N/A
0N/A /**
0N/A * Constructs a new SunParser object.
0N/A */
0N/A SunFileWriter(AudioFileFormat.Type types[]) {
0N/A this.types = types;
0N/A }
0N/A
0N/A
0N/A
0N/A // METHODS TO IMPLEMENT AudioFileWriter
0N/A
0N/A // new, 10.27.99
0N/A
6321N/A public final AudioFileFormat.Type[] getAudioFileTypes(){
0N/A AudioFileFormat.Type[] localArray = new AudioFileFormat.Type[types.length];
0N/A System.arraycopy(types, 0, localArray, 0, types.length);
0N/A return localArray;
0N/A }
0N/A
0N/A
0N/A public abstract AudioFileFormat.Type[] getAudioFileTypes(AudioInputStream stream);
0N/A
0N/A public abstract int write(AudioInputStream stream, AudioFileFormat.Type fileType, OutputStream out) throws IOException;
0N/A
0N/A public abstract int write(AudioInputStream stream, AudioFileFormat.Type fileType, File out) throws IOException;
0N/A
0N/A
0N/A // HELPER METHODS
0N/A
0N/A
0N/A /**
0N/A * rllong
0N/A * Protected helper method to read 64 bits and changing the order of
0N/A * each bytes.
0N/A * @param DataInputStream
0N/A * @return 32 bits swapped value.
0N/A * @exception IOException
0N/A */
6321N/A final int rllong(DataInputStream dis) throws IOException {
0N/A
0N/A int b1, b2, b3, b4 ;
0N/A int i = 0;
0N/A
0N/A i = dis.readInt();
0N/A
0N/A b1 = ( i & 0xFF ) << 24 ;
0N/A b2 = ( i & 0xFF00 ) << 8;
0N/A b3 = ( i & 0xFF0000 ) >> 8;
0N/A b4 = ( i & 0xFF000000 ) >>> 24;
0N/A
0N/A i = ( b1 | b2 | b3 | b4 );
0N/A
0N/A return i;
0N/A }
0N/A
0N/A /**
0N/A * big2little
0N/A * Protected helper method to swap the order of bytes in a 32 bit int
0N/A * @param int
0N/A * @return 32 bits swapped value
0N/A */
6321N/A final int big2little(int i) {
0N/A
0N/A int b1, b2, b3, b4 ;
0N/A
0N/A b1 = ( i & 0xFF ) << 24 ;
0N/A b2 = ( i & 0xFF00 ) << 8;
0N/A b3 = ( i & 0xFF0000 ) >> 8;
0N/A b4 = ( i & 0xFF000000 ) >>> 24;
0N/A
0N/A i = ( b1 | b2 | b3 | b4 );
0N/A
0N/A return i;
0N/A }
0N/A
0N/A /**
0N/A * rlshort
0N/A * Protected helper method to read 16 bits value. Swap high with low byte.
0N/A * @param DataInputStream
0N/A * @return the swapped value.
0N/A * @exception IOException
0N/A */
6321N/A final short rlshort(DataInputStream dis) throws IOException {
0N/A
0N/A short s=0;
0N/A short high, low;
0N/A
0N/A s = dis.readShort();
0N/A
0N/A high = (short)(( s & 0xFF ) << 8) ;
0N/A low = (short)(( s & 0xFF00 ) >>> 8);
0N/A
0N/A s = (short)( high | low );
0N/A
0N/A return s;
0N/A }
0N/A
0N/A /**
0N/A * big2little
0N/A * Protected helper method to swap the order of bytes in a 16 bit short
0N/A * @param int
0N/A * @return 16 bits swapped value
0N/A */
6321N/A final short big2littleShort(short i) {
0N/A
0N/A short high, low;
0N/A
0N/A high = (short)(( i & 0xFF ) << 8) ;
0N/A low = (short)(( i & 0xFF00 ) >>> 8);
0N/A
0N/A i = (short)( high | low );
0N/A
0N/A return i;
0N/A }
0N/A
3628N/A /**
3628N/A * InputStream wrapper class which prevent source stream from being closed.
3628N/A * The class is usefull for use with SequenceInputStream to prevent
3628N/A * closing of the source input streams.
3628N/A */
6321N/A final class NoCloseInputStream extends InputStream {
3628N/A private final InputStream in;
3628N/A
6321N/A NoCloseInputStream(InputStream in) {
3628N/A this.in = in;
3628N/A }
3628N/A
3628N/A @Override
3628N/A public int read() throws IOException {
3628N/A return in.read();
3628N/A }
3628N/A
3628N/A @Override
3628N/A public int read(byte b[]) throws IOException {
3628N/A return in.read(b);
3628N/A }
3628N/A
3628N/A @Override
3628N/A public int read(byte b[], int off, int len) throws IOException {
3628N/A return in.read(b, off, len);
3628N/A }
3628N/A
3628N/A @Override
3628N/A public long skip(long n) throws IOException {
3628N/A return in.skip(n);
3628N/A }
3628N/A
3628N/A @Override
3628N/A public int available() throws IOException {
3628N/A return in.available();
3628N/A }
3628N/A
3628N/A @Override
3628N/A public void close() throws IOException {
3628N/A // don't propagate the call
3628N/A }
3628N/A
3628N/A @Override
3628N/A public void mark(int readlimit) {
3628N/A in.mark(readlimit);
3628N/A }
3628N/A
3628N/A @Override
3628N/A public void reset() throws IOException {
3628N/A in.reset();
3628N/A }
3628N/A
3628N/A @Override
3628N/A public boolean markSupported() {
3628N/A return in.markSupported();
3628N/A }
3628N/A
3628N/A }
0N/A}