2 * This file is part of the Vamsas Client version 0.1.
\r
3 * Copyright 2009 by Jim Procter, Iain Milne, Pierre Marguerite,
\r
4 * Andrew Waterhouse and Dominik Lindner.
\r
6 * Earlier versions have also been incorporated into Jalview version 2.4
\r
7 * since 2008, and TOPALi version 2 since 2007.
\r
9 * The Vamsas Client is free software: you can redistribute it and/or modify
\r
10 * it under the terms of the GNU Lesser General Public License as published by
\r
11 * the Free Software Foundation, either version 3 of the License, or
\r
12 * (at your option) any later version.
\r
14 * The Vamsas Client is distributed in the hope that it will be useful,
\r
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
17 * GNU Lesser General Public License for more details.
\r
19 * You should have received a copy of the GNU Lesser General Public License
\r
20 * along with the Vamsas Client. If not, see <http://www.gnu.org/licenses/>.
\r
22 package uk.ac.vamsas.client.simpleclient;
\r
24 import java.io.File;
\r
25 import java.io.FileDescriptor;
\r
26 import java.io.FileNotFoundException;
\r
27 import java.io.FileOutputStream;
\r
28 import java.io.IOException;
\r
29 import java.io.OutputStream;
\r
30 import java.nio.channels.FileChannel;
\r
32 import org.apache.commons.logging.LogFactory;
\r
38 public class LockedFileOutputStream extends FileOutputStream {
\r
39 private static org.apache.commons.logging.Log log = LogFactory
\r
40 .getLog(LockedFileOutputStream.class);
\r
42 // FileOutputStream ostream=null;
\r
43 boolean closed = true;
\r
45 private void init() {
\r
46 FileChannel ch = super.getChannel();
\r
49 closed = !ch.isOpen();
\r
50 } catch (Exception e) {
\r
52 log.debug("Invalid LockedOutputStream marked closed.", e);
\r
59 * @throws FileNotFoundException
\r
61 public LockedFileOutputStream(File file) throws FileNotFoundException {
\r
62 super(file); // super(file);
\r
69 * @throws FileNotFoundException
\r
71 public LockedFileOutputStream(File file, boolean append)
\r
72 throws FileNotFoundException {
\r
73 super(file, append);
\r
80 public LockedFileOutputStream(FileDescriptor fdObj) {
\r
89 * @throws FileNotFoundException
\r
91 public LockedFileOutputStream(String name) throws FileNotFoundException {
\r
99 * @throws FileNotFoundException
\r
101 public LockedFileOutputStream(String name, boolean append)
\r
102 throws FileNotFoundException {
\r
103 super(name, append);
\r
108 * closes - actually just flushes the stream instead.
\r
110 public void close() throws IOException {
\r
113 super.getChannel().force(true);
\r
114 log.debug("Marking Lockedoutputstream closed.");
\r
116 throw new IOException("Close on already closed FileOutputStream.");
\r
121 * @throws IOException
\r
122 * @see java.io.OutputStream#flush()
\r
124 public void flush() throws IOException {
\r
128 throw new IOException("flush on closed FileOutputStream");
\r
133 * @see java.io.FileOutputStream#getChannel()
\r
135 public FileChannel getChannel() {
\r
137 return super.getChannel();
\r
146 * @throws IOException
\r
147 * @see java.io.FileOutputStream#write(byte[], int, int)
\r
149 public void write(byte[] b, int off, int len) throws IOException {
\r
151 super.write(b, off, len);
\r
153 throw new IOException("write on Closed FileOutputStream");
\r
158 * @throws IOException
\r
159 * @see java.io.FileOutputStream#write(byte[])
\r
161 public void write(byte[] b) throws IOException {
\r
165 throw new IOException("write on Closed FileOutputStream");
\r
170 * @throws IOException
\r
171 * @see java.io.FileOutputStream#write(int)
\r
173 public void write(int b) throws IOException {
\r
177 throw new IOException("write on Closed FileOutputStream");
\r