⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smsclink.java

📁 开放源码的smpp协议开发包
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     *            true to send the optional parameters over the link too, false     *            to only send the mandatory parameters.     * @throws java.io.IOException     *             if an exception occurs during writing or if the connection is     *             not open.     */    public void write(SMPPPacket pak, boolean withOptional)            throws java.io.IOException {        if (out == null)            throw new IOException("Link not established.");        synchronized (writeLock) {            try {                if (snoopOut != null)                    pak.writeTo(snoopOut);            } catch (IOException x) {                logger.warn("IOException writing to snoop output stream.", x);            }            pak.writeTo(out);            if (autoFlush)                out.flush();        }    }    /**     * Flush the output stream of the SMSC link.     *      * @throws java.io.IOException     *             If an exception occurs while flushing the output stream.     */    public void flush() throws java.io.IOException {        if (out != null)            out.flush();    }    /**     * Get the auto flush behaviour of this link. The default behaviour is     * defined in the smppapi properties file. If no properties are found at     * runtime, the default behaviour is set to <code>true</code>.     *      * @see #setAutoFlush     * @see ie.omk.smpp.util.APIConfig     */    public boolean getAutoFlush() {        return (autoFlush);    }    /**     * Set the auto flush behaviour of this link. If set to true, the link will     * flush the output stream after every packet written. In high-load     * environments this may be undesirable.     *      * @see #getAutoFlush     */    public void setAutoFlush(boolean flush) {        this.autoFlush = flush;    }    /**     * Read the next SMPP packet from the SMSC. This method will block until a     * full packet can be read from the SMSC. The caller should pass in a byte     * array to read the packet into. If the passed in byte array is too small,     * a new one will be allocated and returned to the caller.     *      * @param buf     *            a byte array buffer to read the packet into.     * @return the handle to the passed in buffer or the reallocated one.     * @throws java.io.EOFException     *             If the end of stream is reached before a full packet can be     *             read.     * @throws java.io.IOException     *             If an exception occurs when reading the packet from the input     *             stream.     */    public byte[] read(byte[] buf) throws java.io.EOFException,            java.io.IOException {        int ptr = 0, c = 0, cmdLen = 0;        if (in == null)            throw new IOException("Link not established.");        synchronized (readLock) {            try {                if ((ptr = in.read(buf, 0, 16)) < 4) {                    if (ptr == -1)                        throw new EOFException("EOS reached. No data "                                + "available");                    while (ptr < 4) {                        if ((c = in.read(buf, ptr, 16 - ptr)) < 0)                            throw new EOFException("EOS reached. No data "                                    + "available");                        ptr += c;                    }                }                cmdLen = SMPPIO.bytesToInt(buf, 0, 4);                if (cmdLen > buf.length) {                    byte[] newbuf = new byte[cmdLen];                    System.arraycopy(buf, 0, newbuf, 0, ptr);                    buf = newbuf;                }                c = in.read(buf, ptr, cmdLen - ptr);                if (c == -1)                    throw new EOFException("EOS reached. No data available.");                ptr += c;                while (ptr < cmdLen) {                    if ((c = in.read(buf, ptr, cmdLen - ptr)) < 0)                        throw new EOFException("EOS reached. No data available");                    ptr += c;                }            } catch (IOException x) {                // After the finally clause, make sure the caller still gets the                // IOException..                throw x;            } finally {                dump(snoopIn, buf, 0, ptr);            }        }        return (buf);    }    /**     * Get the number of bytes currently available on the input stream.     */    public final int available() {        try {            synchronized (readLock) {                return (in.available());            }        } catch (IOException x) {            logger.debug("IOException in available", x);            return (0);        }    }    /**     * Dump bytes to an output stream.     *      * @param s     *            the stream to write to (if null, do nothing).     * @param b     *            the byte array to dump bytes from.     * @param offset     *            the offset in <code>b</code> to begin from.     * @param len     *            the number of bytes to dump.     */    private void dump(OutputStream s, byte[] b, int offset, int len) {        try {            if (s != null)                s.write(b, offset, len);        } catch (IOException x) {            logger.warn("Couldn't write incoming bytes to input snooper.", x);        }    }    /**     * Get the output stream of the virtual circuit.     *      * @throws java.io.IOException     *             If the output stream cannot be retrieved or the connection is     *             not open.     */    protected abstract OutputStream getOutputStream()            throws java.io.IOException;    /**     * Get the input stream of the virtual circuit.     *      * @throws java.io.IOException     *             If the input stream cannot be retrieved or the connection is     *             not open.     */    protected abstract InputStream getInputStream() throws java.io.IOException;    /**     * Check whether or not the connection to the SMSC is open.     */    public abstract boolean isConnected();    /**     * Set the value for read timeout. A link implementation may support timing     * out on blocking read operations. This method may be used to set such a     * timeout. If the implementation does not support timeouts, it must throw     * an <code>UnsuppertedOperationException<code>.     * @param timeout the timeout value in milliseconds.     * @throws UnsupportedOperationException if the implementation does not support     * timeouts.     */    public void setTimeout(long timeout) throws UnsupportedOperationException {        throw new UnsupportedOperationException("Timeout not supported");    }    /**     * Get the value for read timeout.     *      * @see #setTimeout     * @return the current value for read timeout.     * @throws UnsupportedOperationException     *             if the implementation does not support timeouts.     */    public long getTimeout() throws UnsupportedOperationException {        throw new UnsupportedOperationException("Timeout not supported");    }    /**     * Set the snooper streams. The snooper streams will receive every byte that     * is either received or sent using this class. This functionality is     * intended as a debugging aid for SMPP developers. It will be up to the     * application using the API to provide valid output streams for the data to     * be written to. Either or both of the streams may be set to null, which in     * effect turns off snooping.     *      * @param snoopIn     *            stream to receive incoming bytes from the SMSC (may be null).     * @param snoopOut     *            stream to receive outgoing bytes to the SMSC (may be null).     */    public void setSnoopStreams(OutputStream snoopIn, OutputStream snoopOut) {        this.snoopIn = snoopIn;        this.snoopOut = snoopOut;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -