changes to MGC class library
[IRC.git] / Robust / src / ClassLibrary / FileOutputStream.java
index 04c589c3b74dd907e8b245c2b7c63369c9917ae0..78fe1bb9f455d0823dc7be947e9c25b20de50a89 100644 (file)
@@ -1,29 +1,63 @@
-public class FileOutputStream {
-    private int fd;
-
-    public FileOutputStream(String pathname) {
-       fd=nativeOpen(pathname.getBytes());
-    }
-
-    public FileOutputStream(File path) {
-       fd=nativeOpen(path.getPath().getBytes());
-    }
-
-    private static native int nativeOpen(byte[] filename);
-    private static native void nativeWrite(int fd, byte[] array);
-    private static native void nativeClose(int fd);
-    
-    public void write(int ch) {
-       byte b[]=new byte[1];
-       b[0]=(byte)ch;
-       write(b);
-    }
-
-    public void write(byte[] b) {
-       nativeWrite(fd, b);
-    }
-
-    public void close() {
-       nativeClose(fd);
-    }
+//import java.io.FileDescriptor;
+
+public class FileOutputStream extends OutputStream {
+  private int fd;
+
+  public FileOutputStream(String pathname) {
+    fd=nativeOpen(pathname.getBytes());
+  }
+
+  public FileOutputStream(String pathname, boolean append) {
+    if(append)
+      fd=nativeAppend(pathname.getBytes());
+    else
+      fd=nativeOpen(pathname.getBytes());
+  }
+
+  public FileOutputStream(String pathname, int mode) {
+    if(mode==0)
+      fd=nativeAppend(pathname.getBytes());
+    if(mode==1)
+      fd=nativeOpen(pathname.getBytes());
+  }
+
+  public FileOutputStream(File path) {
+    fd=nativeOpen(path.getPath().getBytes());
+  }
+
+  public FileOutputStreamOpen(String pathname) {
+    fd = nativeOpen(pathname.getBytes());
+  }
+
+  public FileOutputStream(FileDescriptor fdObj) {
+    fd = nativeOpen(fdObj.channel.getBytes());
+  }
+
+  private static native int nativeOpen(byte[] filename);
+  private static native int nativeAppend(byte[] filename);
+  private static native void nativeWrite(int fd, byte[] array, int off, int len);
+  private static native void nativeClose(int fd);
+  private static native void nativeFlush(int fd);
+
+  public void write(int ch) {
+    byte b[]=new byte[1];
+    b[0]=(byte)ch;
+    write(b);
+  }
+
+  public void write(byte[] b) {
+    nativeWrite(fd, b, 0, b.length);
+  }
+
+  public void write(byte[] b, int index, int len) {
+    nativeWrite(fd, b, index, len);
+  }
+
+  public void flush() {
+    nativeFlush(fd);
+  }
+
+  public void close() {
+    nativeClose(fd);
+  }
 }