KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > osgi > storagemanager > ManagedOutputStream


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.osgi.storagemanager;
12
13 import java.io.*;
14
15 /**
16  * Represents a managed output stream for target managed by a storage manager.
17  * @see StorageManager#getOutputStream(String)
18  * @see StorageManager#getOutputStreamSet(String[])
19  * <p>
20  * Clients may not extend this class.
21  * </p>
22  * @since 3.2
23  */

24 // Note the implementation of this class originated from the following deprecated classes:
25
// /org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/adaptor/StreamManagerOutputStream.java
26
public final class ManagedOutputStream extends FilterOutputStream {
27     static final int ST_OPEN = 0;
28     static final int ST_CLOSED = 1;
29     private String JavaDoc target;
30     private StorageManager manager;
31     private File outputFile;
32     private int state;
33     private ManagedOutputStream[] streamSet = null;
34
35     ManagedOutputStream(OutputStream out, StorageManager manager, String JavaDoc target, File outputFile) {
36         super(out);
37         this.manager = manager;
38         this.target = target;
39         this.outputFile = outputFile;
40         this.state = ST_OPEN;
41     }
42
43     /**
44      * Instructs this output stream to be closed and storage manager to
45      * be updated as appropriate. If this managed output stream is part of
46      * a set returned by {@link StorageManager#getOutputStreamSet(String[])} then
47      * the storage manager will only be updated with the new content after all
48      * of the managed output streams in the set are closed successfully.
49      * @see FilterOutputStream#close()
50      */

51     public void close() throws IOException {
52         manager.closeOutputStream(this);
53     }
54
55     /**
56      * Instructs this output stream to be closed and the contents discarded.
57      * If this managed output stream is part of a set returned by
58      * {@link StorageManager#getOutputStreamSet(String[])} then the new
59      * content of all managed output streams in the set will be discarded.
60      */

61     public void abort() {
62         manager.abortOutputStream(this);
63     }
64
65     OutputStream getOutputStream() {
66         return out;
67     }
68
69     String JavaDoc getTarget() {
70         return target;
71     }
72
73     File getOutputFile() {
74         return outputFile;
75     }
76
77     int getState() {
78         return state;
79     }
80
81     void setState(int state) {
82         this.state = state;
83     }
84
85     void setStreamSet(ManagedOutputStream[] set) {
86         streamSet = set;
87     }
88
89     ManagedOutputStream[] getStreamSet() {
90         return streamSet;
91     }
92
93     /*
94      * (non-Javadoc)
95      * @see java.io.FilterOutputStream#write(byte[], int, int)
96      * Override this method to prevent single byte writes to the output stream
97      * which is done by the default implementation of FilteredOutputStream
98      */

99     public void write(byte[] bytes, int off, int len) throws IOException {
100         out.write(bytes, off, len);
101     }
102 }
103
Popular Tags