@Override public OutputStream createOutgoingStream(String streamID, Jid initiator, Jid target) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { InBandBytestreamSession session = this.manager.establishSession(target, streamID); session.setCloseBothStreamsEnabled(true); return session.getOutputStream(); }
@Override public void close() throws IOException { if (closeInvoked) { return; } this.closeInvoked = true; InBandBytestreamSession.this.closeByLocal(true); }
@Override public void newStreamInitiation(Jid from, String streamID) { /* * this method is always called prior to #negotiateIncomingStream() so * the In-Band Bytestream initiation listener must ignore the next * In-Band Bytestream request with the given session ID */ this.manager.ignoreBytestreamRequestOnce(streamID); }
@Test public void shouldReturnSession() throws Exception { InBandBytestreamManager byteStreamManager = InBandBytestreamManager.getByteStreamManager(connection); IQ success = IBBPacketUtils.createResultIQ(targetJID, initiatorJID); protocol.addResponse(success, Verification.correspondingSenderReceiver, Verification.requestTypeSET); // start In-Band Bytestream InBandBytestreamSession session = byteStreamManager.establishSession(targetJID); assertNotNull(session); assertNotNull(session.getInputStream()); assertNotNull(session.getOutputStream()); protocol.verifyAll(); }
@Override InputStream negotiateIncomingStream(Stanza streamInitiation) throws NotConnectedException, InterruptedException { // build In-Band Bytestream request InBandBytestreamRequest request = new ByteStreamRequest(this.manager, (Open) streamInitiation); // always accept the request InBandBytestreamSession session = request.accept(); session.setCloseBothStreamsEnabled(true); return session.getInputStream(); }
/** * Constructor. * * @param connection the XMPP connection */ private InBandBytestreamManager(XMPPConnection connection) { super(connection); // register bytestream open packet listener this.initiationListener = new InitiationListener(this); connection.registerIQRequestHandler(initiationListener); // register bytestream data packet listener this.dataListener = new DataListener(this); connection.registerIQRequestHandler(dataListener); // register bytestream close packet listener this.closeListener = new CloseListener(this); connection.registerIQRequestHandler(closeListener); }
@Override public synchronized int read() throws IOException { checkClosed(); // if nothing read yet or whole buffer has been read fill buffer if (bufferPointer == -1 || bufferPointer >= buffer.length) { // if no data available and stream was closed return -1 if (!loadBuffer()) { return -1; } } // return byte and increment buffer pointer return buffer[bufferPointer++] & 0xff; }
/** * Constructor. */ protected IBBInputStream() { // add data packet listener to connection this.dataPacketListener = getDataPacketListener(); connection.addSyncStanzaListener(this.dataPacketListener, getDataPacketFilter()); }
@Test(expected = IllegalArgumentException.class) public void shouldNotAllowTooBigDefaultBlockSize() { InBandBytestreamManager byteStreamManager = InBandBytestreamManager.getByteStreamManager(connection); byteStreamManager.setDefaultBlockSize(1000000); }
/** * The default constructor for the In-Band Bytestream Negotiator. * * @param connection The connection which this negotiator works on. */ protected IBBTransferNegotiator(XMPPConnection connection) { super(connection); this.manager = InBandBytestreamManager.getByteStreamManager(connection); }
@Test(expected = IllegalArgumentException.class) public void shouldNotAllowTooBigMaximumBlockSize() { InBandBytestreamManager byteStreamManager = InBandBytestreamManager.getByteStreamManager(connection); byteStreamManager.setMaximumBlockSize(1000000); }
@Override public void incomingBytestreamRequest(BytestreamRequest request) { incomingBytestreamRequest((InBandBytestreamRequest) request); }
@Override public synchronized void write(int b) throws IOException { if (this.isClosed) { throw new IOException("Stream is closed"); } // if buffer is full flush buffer if (bufferPointer >= buffer.length) { flushBuffer(); } buffer[bufferPointer++] = (byte) b; }
/** * Rejects the In-Band Bytestream request by sending a reject error to the * initiator. * @throws NotConnectedException * @throws InterruptedException */ @Override public void reject() throws NotConnectedException, InterruptedException { this.manager.replyRejectPacket(this.byteStreamRequest); }
@Override public synchronized int read(byte[] b) throws IOException { return read(b, 0, b.length); }
@Override public synchronized void write(byte[] b) throws IOException { write(b, 0, b.length); }
/** * Returns the XMPP connection. * * @return the XMPP connection */ protected XMPPConnection getConnection() { return connection(); }
@Override public void close() throws IOException { closeByLocal(true); // close input stream closeByLocal(false); // close output stream }
@Override public synchronized void flush() throws IOException { if (this.isClosed) { throw new IOException("Stream is closed"); } flushBuffer(); }
@Override public void close() throws IOException { if (isClosed) { return; } InBandBytestreamSession.this.closeByLocal(false); }