1 /*
2 * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
202 dos.writeInt(AuFileFormat.AU_SUN_MAGIC);
203 dos.writeInt(headerSize);
204 dos.writeInt((int) dataSizeInBytes);
205 dos.writeInt(auType);
206 dos.writeInt(sampleRate);
207 dos.writeInt(channels);
208 header = baos.toByteArray();
209 }
210 // Now create a new InputStream from headerStream and the InputStream
211 // in audioStream
212 return new SequenceInputStream(new ByteArrayInputStream(header),
213 new NoCloseInputStream(audioStream));
214 }
215
216 private int writeAuFile(AudioInputStream in, AuFileFormat auFileFormat,
217 OutputStream out) throws IOException {
218
219 int bytesRead = 0;
220 int bytesWritten = 0;
221 InputStream fileStream = getFileStream(auFileFormat, in);
222 byte buffer[] = new byte[bisBufferSize];
223 int maxLength = auFileFormat.getByteLength();
224
225 while( (bytesRead = fileStream.read( buffer )) >= 0 ) {
226 if (maxLength>0) {
227 if( bytesRead < maxLength ) {
228 out.write( buffer, 0, bytesRead );
229 bytesWritten += bytesRead;
230 maxLength -= bytesRead;
231 } else {
232 out.write( buffer, 0, maxLength );
233 bytesWritten += maxLength;
234 maxLength = 0;
235 break;
236 }
237 } else {
238 out.write( buffer, 0, bytesRead );
239 bytesWritten += bytesRead;
240 }
241 }
242
|
1 /*
2 * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
202 dos.writeInt(AuFileFormat.AU_SUN_MAGIC);
203 dos.writeInt(headerSize);
204 dos.writeInt((int) dataSizeInBytes);
205 dos.writeInt(auType);
206 dos.writeInt(sampleRate);
207 dos.writeInt(channels);
208 header = baos.toByteArray();
209 }
210 // Now create a new InputStream from headerStream and the InputStream
211 // in audioStream
212 return new SequenceInputStream(new ByteArrayInputStream(header),
213 new NoCloseInputStream(audioStream));
214 }
215
216 private int writeAuFile(AudioInputStream in, AuFileFormat auFileFormat,
217 OutputStream out) throws IOException {
218
219 int bytesRead = 0;
220 int bytesWritten = 0;
221 InputStream fileStream = getFileStream(auFileFormat, in);
222 byte[] buffer = new byte[bisBufferSize];
223 int maxLength = auFileFormat.getByteLength();
224
225 while( (bytesRead = fileStream.read( buffer )) >= 0 ) {
226 if (maxLength>0) {
227 if( bytesRead < maxLength ) {
228 out.write( buffer, 0, bytesRead );
229 bytesWritten += bytesRead;
230 maxLength -= bytesRead;
231 } else {
232 out.write( buffer, 0, maxLength );
233 bytesWritten += maxLength;
234 maxLength = 0;
235 break;
236 }
237 } else {
238 out.write( buffer, 0, bytesRead );
239 bytesWritten += bytesRead;
240 }
241 }
242
|