001: /**
002: * @copyright
003: * ====================================================================
004: * Copyright (c) 2003 CollabNet. All rights reserved.
005: *
006: * This software is licensed as described in the file COPYING, which
007: * you should have received as part of this distribution. The terms
008: * are also available at http://subversion.tigris.org/license-1.html.
009: * If newer versions of this license are posted there, you may use a
010: * newer version instead, at your option.
011: *
012: * This software consists of voluntary contributions made by many
013: * individuals. For exact contribution history, see the revision
014: * history and logs, available at http://subversion.tigris.org/.
015: * ====================================================================
016: * @endcopyright
017: */package org.tigris.subversion.javahl;
018:
019: import java.io.*;
020:
021: /**
022: * This class connects a java.io.PipedOutputStream to a InputInterface.
023: * The outherside of the Pipe must written by another thread, or deadlocks
024: * will occure
025: */
026: public class SVNOutputStream extends PipedOutputStream {
027: /**
028: * my connection to receive data into subversion
029: */
030: Inputer myInputer;
031:
032: /**
033: * Creates a SVNOutputStream so that it is connected with an internal
034: * PipedInputStream
035: * @throws IOException
036: */
037: public SVNOutputStream() throws IOException {
038: myInputer = new Inputer(this );
039: }
040:
041: /**
042: * Closes this piped output stream and releases any system resources
043: * associated with this stream. This stream may no longer be used for
044: * writing bytes.
045: *
046: * @exception IOException if an I/O error occurs.
047: */
048: public void close() throws IOException {
049: myInputer.closed = true;
050: super .close();
051: }
052:
053: /**
054: * Get the Interface to connect to SVNAdmin
055: * @return the connetion interface
056: */
057: public InputInterface getInputer() {
058: return myInputer;
059: }
060:
061: /**
062: * this class implements the connection to SVNAdmin
063: */
064: public class Inputer implements InputInterface {
065: /**
066: * my side of the pipe
067: */
068: PipedInputStream myStream;
069: /**
070: * flag that the other side of the pipe has been closed
071: */
072: boolean closed;
073:
074: /**
075: * build a new connection object
076: * @param myMaster the other side of the pipe
077: * @throws IOException
078: */
079: Inputer(SVNOutputStream myMaster) throws IOException {
080: myStream = new PipedInputStream(myMaster);
081: }
082:
083: /**
084: * read the number of data.length bytes from input.
085: * @param data array to store the read bytes.
086: * @throws IOException throw in case of problems.
087: */
088: public int read(byte[] data) throws IOException {
089: if (closed)
090: throw new IOException("stream has been closed");
091: return myStream.read();
092: }
093:
094: /**
095: * close the input
096: * @throws IOException throw in case of problems.
097: */
098: public void close() throws IOException {
099: myStream.close();
100: }
101: }
102: }
|