4 package uk.ac.vamsas.client.simpleclient;
\r
7 import java.io.FileDescriptor;
\r
8 import java.io.FileNotFoundException;
\r
9 import java.io.FileOutputStream;
\r
10 import java.io.IOException;
\r
11 import java.io.OutputStream;
\r
12 import java.nio.channels.FileChannel;
\r
14 import org.apache.commons.logging.LogFactory;
\r
20 public class LockedFileOutputStream extends FileOutputStream {
\r
21 private static org.apache.commons.logging.Log log = LogFactory.getLog(LockedFileOutputStream.class);
\r
22 //FileOutputStream ostream=null;
\r
23 boolean closed=true;
\r
24 private void init() {
\r
25 FileChannel ch = super.getChannel();
\r
27 try { closed = !ch.isOpen();
\r
28 } catch (Exception e) {
\r
30 log.debug("Invalid LockedOutputStream marked closed.",e);
\r
36 * @throws FileNotFoundException
\r
38 public LockedFileOutputStream(File file) throws FileNotFoundException {
\r
39 super(file); // super(file);
\r
46 * @throws FileNotFoundException
\r
48 public LockedFileOutputStream(File file, boolean append)
\r
49 throws FileNotFoundException {
\r
50 super(file, append);
\r
57 public LockedFileOutputStream(FileDescriptor fdObj) {
\r
66 * @throws FileNotFoundException
\r
68 public LockedFileOutputStream(String name) throws FileNotFoundException {
\r
76 * @throws FileNotFoundException
\r
78 public LockedFileOutputStream(String name, boolean append)
\r
79 throws FileNotFoundException {
\r
80 super(name, append);
\r
84 * closes - actually just flushes the stream instead.
\r
86 public void close() throws IOException {
\r
89 super.getChannel().force(true);
\r
90 log.debug("Marking Lockedoutputstream closed.");
\r
92 throw new IOException("Close on already closed FileOutputStream.");
\r
98 * @throws IOException
\r
99 * @see java.io.OutputStream#flush()
\r
101 public void flush() throws IOException {
\r
105 throw new IOException("flush on closed FileOutputStream");
\r
110 * @see java.io.FileOutputStream#getChannel()
\r
112 public FileChannel getChannel() {
\r
114 return super.getChannel();
\r
125 * @throws IOException
\r
126 * @see java.io.FileOutputStream#write(byte[], int, int)
\r
128 public void write(byte[] b, int off, int len) throws IOException {
\r
130 super.write(b, off, len);
\r
132 throw new IOException("write on Closed FileOutputStream");
\r
137 * @throws IOException
\r
138 * @see java.io.FileOutputStream#write(byte[])
\r
140 public void write(byte[] b) throws IOException {
\r
144 throw new IOException("write on Closed FileOutputStream");
\r
149 * @throws IOException
\r
150 * @see java.io.FileOutputStream#write(int)
\r
152 public void write(int b) throws IOException {
\r
156 throw new IOException("write on Closed FileOutputStream");
\r