Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a270694a46b3664494c7ff365aa4121ffdbd2452 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*******************************************************************************
 * Copyright (c) 2005, 2008 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.osgi.storagemanager;

import java.io.*;

/**
 * Represents a managed output stream for target managed by a storage manager.
 * @see StorageManager#getOutputStream(String)
 * @see StorageManager#getOutputStreamSet(String[])
 * <p>
 * Clients may not extend this class.
 * </p>
 * @since 3.2
 */
// Note the implementation of this class originated from the following deprecated classes:
// /org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/adaptor/StreamManagerOutputStream.java
public final class ManagedOutputStream extends FilterOutputStream {
	static final int ST_OPEN = 0;
	static final int ST_CLOSED = 1;
	private String target;
	private StorageManager manager;
	private File outputFile;
	private int state;
	private ManagedOutputStream[] streamSet = null;

	ManagedOutputStream(OutputStream out, StorageManager manager, String target, File outputFile) {
		super(out);
		this.manager = manager;
		this.target = target;
		this.outputFile = outputFile;
		this.state = ST_OPEN;
	}

	/** 
	 * Instructs this output stream to be closed and storage manager to 
	 * be updated as appropriate.  If this managed output stream is part of 
	 * a set returned by {@link StorageManager#getOutputStreamSet(String[])} then
	 * the storage manager will only be updated with the new content after all 
	 * of the managed output streams in the set are closed successfully.
	 * @see FilterOutputStream#close()
	 */
	public void close() throws IOException {
		manager.closeOutputStream(this);
	}

	/**
	 * Instructs this output stream to be closed and the contents discarded.
	 * If this managed output stream is part of a set returned by 
	 * {@link StorageManager#getOutputStreamSet(String[])} then the new 
	 * content of all managed output streams in the set will be discarded.
	 */
	public void abort() {
		manager.abortOutputStream(this);
	}

	OutputStream getOutputStream() {
		return out;
	}

	String getTarget() {
		return target;
	}

	File getOutputFile() {
		return outputFile;
	}

	int getState() {
		return state;
	}

	void setState(int state) {
		this.state = state;
	}

	void setStreamSet(ManagedOutputStream[] set) {
		streamSet = set;
	}

	ManagedOutputStream[] getStreamSet() {
		return streamSet;
	}

	/*
	 * (non-Javadoc)
	 * @see java.io.FilterOutputStream#write(byte[], int, int)
	 * Override this method to prevent single byte writes to the output stream
	 * which is done by the default implementation of FilteredOutputStream
	 */
	public void write(byte[] bytes, int off, int len) throws IOException {
		out.write(bytes, off, len);
	}
}

Back to the top