blob: aceecb441a2854279cee29d7af28f0c9e12478af (
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
|
/*******************************************************************************
* Copyright (c) 2009 Clark N. Hobbie
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Clark N. Hobbie - initial API and implementation
*******************************************************************************/
package org.eclipse.ecf.ipc.fifo;
import java.io.IOException;
import java.io.OutputStream;
import org.eclipse.ecf.ipc.IPCException;
public class FIFOOutputStream extends OutputStream
{
private byte[] myBuffer;
private int myNumberOfBytes;
private FIFO myNamedPipe;
public FIFOOutputStream(FIFO pipe)
{
initialize(pipe);
}
public void initialize(FIFO pipe)
{
myNamedPipe = pipe;
myBuffer = new byte[8192];
myNumberOfBytes = 0;
}
@Override
public void write(int b) throws IOException
{
if (myNumberOfBytes >= myBuffer.length)
{
flush();
}
myBuffer[myNumberOfBytes] = (byte) b;
myNumberOfBytes++;
}
@Override
public void flush() throws IOException
{
try
{
myNamedPipe.write(myBuffer, 0, myNumberOfBytes);
myNumberOfBytes = 0;
}
catch (IPCException e)
{
throw new IOException("Error writing out data", e);
}
}
@Override
public void close() throws IOException
{
flush();
}
}
|