/** * Send file to provided JID via a SOCKS5 Bytestream session (XEP-0065). * * @param file * @param jid * @throws SmackException * @throws InterruptedException * @throws IOException * @throws XMPPException */ public void sendFile(byte[] file, String jid) throws XMPPException, IOException, InterruptedException, SmackException { String jidFinal = getFullJid(jid); jidFinal += "/receiver"; Socks5BytestreamManager bytestreamManager = Socks5BytestreamManager.getBytestreamManager(connection); OutputStream outputStream = null; try { Socks5BytestreamSession session = bytestreamManager.establishSession(jidFinal); outputStream = session.getOutputStream(); outputStream.write(file); outputStream.flush(); } finally { if (outputStream != null) { try { outputStream.close(); } catch (IOException e) { logger.error(e.getMessage(), e); } } } }
@Override InputStream negotiateIncomingStream(Stanza streamInitiation) throws InterruptedException, SmackException, XMPPErrorException { // build SOCKS5 Bytestream request Socks5BytestreamRequest request = new ByteStreamRequest(this.manager, (Bytestream) streamInitiation); // always accept the request Socks5BytestreamSession session = request.accept(); // test input stream try { PushbackInputStream stream = new PushbackInputStream(session.getInputStream()); int firstByte = stream.read(); stream.unread(firstByte); return stream; } catch (IOException e) { throw new SmackException("Error establishing input stream", e); } }
@Override InputStream negotiateIncomingStream(Packet streamInitiation) throws XMPPException, InterruptedException { // build SOCKS5 Bytestream request Socks5BytestreamRequest request = new ByteStreamRequest(this.manager, (Bytestream) streamInitiation); // always accept the request Socks5BytestreamSession session = request.accept(); // test input stream try { PushbackInputStream stream = new PushbackInputStream(session.getInputStream()); int firstByte = stream.read(); stream.unread(firstByte); return stream; } catch (IOException e) { throw new XMPPException("Error establishing input stream", e); } }
@Override InputStream negotiateIncomingStream(Packet streamInitiation) throws XMPPException, InterruptedException { // build SOCKS5 Bytestream request Socks5BytestreamRequest request = new ByteStreamRequest(this.manager, (Bytestream) streamInitiation); // always accept the request Socks5BytestreamSession session = request.accept(); // test input stream try { PushbackInputStream stream = new PushbackInputStream( session.getInputStream()); int firstByte = stream.read(); stream.unread(firstByte); return stream; } catch (IOException e) { throw new XMPPException("Error establishing input stream", e); } }