2008-02-19 18:06:52 +00:00
|
|
|
/* Copyright (c) 2008, Avian Contributors
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software
|
|
|
|
for any purpose with or without fee is hereby granted, provided
|
|
|
|
that the above copyright notice and this permission notice appear
|
|
|
|
in all copies.
|
|
|
|
|
|
|
|
There is NO WARRANTY for this software. See license.txt for
|
|
|
|
details. */
|
|
|
|
|
2007-07-25 00:34:45 +00:00
|
|
|
package java.io;
|
|
|
|
|
|
|
|
public class FileOutputStream extends OutputStream {
|
2008-07-14 03:54:07 +00:00
|
|
|
// static {
|
|
|
|
// System.loadLibrary("natives");
|
|
|
|
// }
|
2007-08-15 01:14:55 +00:00
|
|
|
|
2007-07-27 02:39:53 +00:00
|
|
|
private int fd;
|
2007-07-25 00:34:45 +00:00
|
|
|
|
|
|
|
public FileOutputStream(FileDescriptor fd) {
|
2007-07-26 00:48:28 +00:00
|
|
|
this.fd = fd.value;
|
2007-07-25 00:34:45 +00:00
|
|
|
}
|
|
|
|
|
2007-07-27 00:06:05 +00:00
|
|
|
public FileOutputStream(String path) throws IOException {
|
2010-08-15 01:05:18 +00:00
|
|
|
this(path, false);
|
2007-07-27 00:06:05 +00:00
|
|
|
}
|
|
|
|
|
2010-08-15 01:05:18 +00:00
|
|
|
public FileOutputStream(String path, boolean append) throws IOException {
|
|
|
|
fd = open(path, append);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-27 00:06:05 +00:00
|
|
|
public FileOutputStream(File file) throws IOException {
|
|
|
|
this(file.getPath());
|
|
|
|
}
|
|
|
|
|
2010-08-15 01:05:18 +00:00
|
|
|
private static native int open(String path, boolean append) throws IOException;
|
2007-07-27 00:06:05 +00:00
|
|
|
|
2007-08-30 23:31:32 +00:00
|
|
|
private static native void write(int fd, int c) throws IOException;
|
2007-07-25 00:34:45 +00:00
|
|
|
|
2007-08-30 23:31:32 +00:00
|
|
|
private static native void write(int fd, byte[] b, int offset, int length)
|
2007-07-25 00:34:45 +00:00
|
|
|
throws IOException;
|
|
|
|
|
2007-08-30 23:31:32 +00:00
|
|
|
private static native void close(int fd) throws IOException;
|
2007-07-26 00:48:28 +00:00
|
|
|
|
|
|
|
public void write(int c) throws IOException {
|
|
|
|
write(fd, c);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void write(byte[] b, int offset, int length) throws IOException {
|
2007-07-27 00:06:05 +00:00
|
|
|
if (b == null) {
|
|
|
|
throw new NullPointerException();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (offset < 0 || offset + length > b.length) {
|
|
|
|
throw new ArrayIndexOutOfBoundsException();
|
|
|
|
}
|
|
|
|
|
2007-07-26 00:48:28 +00:00
|
|
|
write(fd, b, offset, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void close() throws IOException {
|
2010-01-10 01:22:16 +00:00
|
|
|
if (fd != -1) {
|
|
|
|
close(fd);
|
|
|
|
fd = -1;
|
|
|
|
}
|
2007-07-26 00:48:28 +00:00
|
|
|
}
|
2007-07-25 00:34:45 +00:00
|
|
|
}
|