< prev index next >
src/java.desktop/share/classes/com/sun/media/sound/RIFFWriter.java
Print this page
@@ -20,10 +20,11 @@
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
+
package com.sun.media.sound;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -37,25 +38,25 @@
*/
public final class RIFFWriter extends OutputStream {
private interface RandomAccessWriter {
- public void seek(long chunksizepointer) throws IOException;
+ void seek(long chunksizepointer) throws IOException;
- public long getPointer() throws IOException;
+ long getPointer() throws IOException;
- public void close() throws IOException;
+ void close() throws IOException;
- public void write(int b) throws IOException;
+ void write(int b) throws IOException;
- public void write(byte[] b, int off, int len) throws IOException;
+ void write(byte[] b, int off, int len) throws IOException;
- public void write(byte[] bytes) throws IOException;
+ void write(byte[] bytes) throws IOException;
- public long length() throws IOException;
+ long length() throws IOException;
- public void setLength(long i) throws IOException;
+ void setLength(long i) throws IOException;
}
private static class RandomAccessFileWriter implements RandomAccessWriter {
RandomAccessFile raf;
@@ -66,38 +67,46 @@
RandomAccessFileWriter(String name) throws FileNotFoundException {
this.raf = new RandomAccessFile(name, "rw");
}
+ @Override
public void seek(long chunksizepointer) throws IOException {
raf.seek(chunksizepointer);
}
+ @Override
public long getPointer() throws IOException {
return raf.getFilePointer();
}
+ @Override
public void close() throws IOException {
raf.close();
}
+ @Override
public void write(int b) throws IOException {
raf.write(b);
}
+ @Override
public void write(byte[] b, int off, int len) throws IOException {
raf.write(b, off, len);
}
+ @Override
public void write(byte[] bytes) throws IOException {
raf.write(bytes);
}
+ @Override
public long length() throws IOException {
return raf.length();
}
+ @Override
public void setLength(long i) throws IOException {
raf.setLength(i);
}
}
@@ -111,48 +120,56 @@
RandomAccessByteWriter(OutputStream stream) {
this.stream = stream;
}
+ @Override
public void seek(long chunksizepointer) throws IOException {
pos = (int) chunksizepointer;
}
+ @Override
public long getPointer() throws IOException {
return pos;
}
+ @Override
public void close() throws IOException {
stream.write(buff, 0, length);
stream.close();
}
+ @Override
public void write(int b) throws IOException {
if (s == null)
s = new byte[1];
s[0] = (byte)b;
write(s, 0, 1);
}
+ @Override
public void write(byte[] b, int off, int len) throws IOException {
int newsize = pos + len;
if (newsize > length)
setLength(newsize);
int end = off + len;
for (int i = off; i < end; i++) {
buff[pos++] = b[i];
}
}
+ @Override
public void write(byte[] bytes) throws IOException {
write(bytes, 0, bytes.length);
}
+ @Override
public long length() throws IOException {
return length;
}
+ @Override
public void setLength(long i) throws IOException {
length = (int) i;
if (length > buff.length) {
int newlen = Math.max(buff.length << 1, length);
byte[] newbuff = new byte[newlen];
@@ -221,10 +238,11 @@
public boolean getWriteOverride() {
return writeoverride;
}
+ @Override
public void close() throws IOException {
if (!open)
return;
if (childchunk != null) {
childchunk.close();
@@ -243,10 +261,11 @@
raf.seek(fpointer);
open = false;
raf = null;
}
+ @Override
public void write(int b) throws IOException {
if (!writeoverride) {
if (chunktype != 2) {
throw new IllegalArgumentException(
"Only chunks can write bytes!");
@@ -257,10 +276,11 @@
}
}
raf.write(b);
}
+ @Override
public void write(byte b[], int off, int len) throws IOException {
if (!writeoverride) {
if (chunktype != 2) {
throw new IllegalArgumentException(
"Only chunks can write bytes!");
< prev index next >