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.IOException;
020: import java.io.PipedInputStream;
021: import java.io.PipedOutputStream;
022:
023: /**
024: * This class connects a java.io.PipedInputStream to a OutputInterface.
025: * The outherside of the Pipe must read by another thread, or deadlocks
026: * will occure
027: */
028: public class SVNInputStream extends PipedInputStream {
029: /**
030: * my connection to put data into subversion
031: */
032: Outputer myOutputer;
033:
034: /**
035: * Creates a SVNInputStream so that it is connected with an internal
036: * PipedOutputStream
037: * @throws IOException
038: */
039: public SVNInputStream() throws IOException {
040: myOutputer = new Outputer(this );
041: }
042:
043: /**
044: * Get the Interface to connect to SVNAdmin
045: * @return the connetion interface
046: */
047: public OutputInterface getOutputer() {
048: return myOutputer;
049: }
050:
051: /**
052: * Closes this input stream and releases any system resources associated
053: * with the stream.
054: *
055: * <p> The <code>close</code> method of <code>InputStream</code> does
056: * nothing.
057: *
058: * @exception IOException if an I/O error occurs.
059: */
060: public void close() throws IOException {
061: myOutputer.closed = true;
062: super .close();
063: }
064:
065: /**
066: * this class implements the connection to SVNAdmin
067: */
068: public class Outputer implements OutputInterface {
069: /**
070: * my side of the pipe
071: */
072: PipedOutputStream myStream;
073: /**
074: * flag that the other side of the pipe has been closed
075: */
076: boolean closed;
077:
078: /**
079: * build a new connection object
080: * @param myMaster the other side of the pipe
081: * @throws IOException
082: */
083: Outputer(SVNInputStream myMaster) throws IOException {
084: myStream = new PipedOutputStream(myMaster);
085: }
086:
087: /**
088: * write the bytes in data to java
089: * @param data the data to be writtem
090: * @throws IOException throw in case of problems.
091: */
092: public int write(byte[] data) throws IOException {
093: if (closed)
094: throw new IOException("stream has been closed");
095: myStream.write(data);
096: return data.length;
097: }
098:
099: /**
100: * close the output
101: * @throws IOException throw in case of problems.
102: */
103: public void close() throws IOException {
104: myStream.close();
105: }
106: }
107: }
|