Example usage for org.apache.thrift.transport TTransportException TTransportException

List of usage examples for org.apache.thrift.transport TTransportException TTransportException

Introduction

In this page you can find the example usage for org.apache.thrift.transport TTransportException TTransportException.

Prototype

public TTransportException(Throwable cause) 

Source Link

Usage

From source file:alluxio.network.thrift.BootstrapClientTransport.java

License:Apache License

@Override
public int read(byte[] buf, int off, int len) throws TTransportException {
    if (!mTransport.isOpen()) {
        throw new TTransportException("transport is not open");
    }/*  w w  w .  j  a  v a 2 s.c om*/
    return mTransport.read(buf, off, len);
}

From source file:alluxio.network.thrift.BootstrapClientTransport.java

License:Apache License

@Override
public void write(byte[] buf, int off, int len) throws TTransportException {
    if (!mTransport.isOpen()) {
        throw new TTransportException("transport is not open");
    }// w  w w  .j  a  v a 2 s.c  o  m
    mTransport.write(buf, off, len);
}

From source file:alluxio.network.thrift.BootstrapClientTransport.java

License:Apache License

@Override
public void flush() throws TTransportException {
    if (!mTransport.isOpen()) {
        throw new TTransportException("transport is not open");
    }//from w  w  w  .ja v  a  2  s.com
    mTransport.flush();
}

From source file:alluxio.network.thrift.BootstrapServerTransport.java

License:Apache License

@Override
public void open() throws TTransportException {
    LOG.debug("opening server transport");
    if (!mBaseTransport.isOpen()) {
        mBaseTransport.open();//from w w w .  j  a v  a 2s. c  o  m
    }
    byte[] messageHeader = new byte[BOOTSTRAP_HEADER.length];
    int bytes;
    try {
        bytes = mBaseTransport.peek(messageHeader, 0, BOOTSTRAP_HEADER.length);
    } catch (TTransportException e) {
        if (e.getType() == TTransportException.END_OF_FILE) {
            LOG.debug("No data in the stream {}", mBaseTransport);
            mBaseTransport.close();
            throw new TTransportException("No data in the stream.");
        }
        throw e;
    }

    if (bytes == BOOTSTRAP_HEADER.length && Arrays.equals(messageHeader, BOOTSTRAP_HEADER)) {
        mBaseTransport.consumeBuffer(BOOTSTRAP_HEADER.length);
        mTransport = mBaseTransport;
    } else {
        mTransport = mTransportFactory.getTransport(mBaseTransport);
    }
    if (!mTransport.isOpen()) {
        mTransport.open();
    }
}

From source file:alluxio.network.thrift.BootstrapServerTransport.java

License:Apache License

@Override
public int read(byte[] buf, int off, int len) throws TTransportException {
    if (!isOpen()) {
        throw new TTransportException("transport is not open: " + mTransport);
    }/*from  w  w  w .j a  v  a  2 s .  co m*/
    return mTransport.read(buf, off, len);
}

From source file:alluxio.network.thrift.BootstrapServerTransport.java

License:Apache License

@Override
public void write(byte[] buf, int off, int len) throws TTransportException {
    if (!isOpen()) {
        throw new TTransportException("transport is not open: " + mTransport);
    }//  w w w  .j  a  va  2s.  com
    mTransport.write(buf, off, len);
}

From source file:alluxio.network.thrift.BootstrapServerTransport.java

License:Apache License

@Override
public void flush() throws TTransportException {
    if (!isOpen()) {
        throw new TTransportException("transport is not open: " + mTransport);
    }/*from   www.j a  va  2 s.c o  m*/
    mTransport.flush();
}

From source file:com.bangcar.app.data.TYgbTransport.java

License:Apache License

private void readFrame() throws TTransportException {
    transport_.readAll(i32buf, 0, 4);/*from  w  w  w  .j  av  a  2 s. c  om*/
    int size = decodeFrameSize(i32buf);

    if (size < 0) {
        throw new TTransportException("Read a negative frame size (" + size + ")!");
    }

    if (size > maxLength_) {
        throw new TTransportException("Frame size (" + size + ") larger than max length (" + maxLength_ + ")!");
    }

    try {
        byte[] buff = new byte[size];
        transport_.readAll(buff, 0, size);
        String text = new String(buff, "utf8");
        buff = Cipher.decrypt(key, text);
        //buff = Base64.decode(rst, Base64.DEFAULT);
        readBuffer_.reset(buff);
    } catch (UnsupportedEncodingException e) {

    }

}

From source file:com.evernote.android.edam.TAndroidHttpClient.java

License:Apache License

/**
 * Create a new TAndroidHttpClient./*  w  w w.  j av a2 s. c  o  m*/
 * 
 * @param url The Thrift server URL, for example, https://www.evernote.com/edam/user.
 * @param userAgent The User-Agent string to send, which should identify the
 * client application.
 * @param tempPath A temp directory where Thrift messages should be cached 
 * before they're sent.
 * 
 * @throws TTransportException If an error occurs creating the temporary
 * file that will be used to cache Thrift messages to disk before sending.
 */
public TAndroidHttpClient(String url, String userAgent, File tempDir) throws TTransportException {

    getHTTPClient();

    LOGGER.info((Thread.currentThread().getId()) + "Constructing Thrift client with user agent:" + userAgent
            + " to URL: " + url);
    this.userAgent = userAgent;
    try {
        url_ = new URL(url);
        requestBuffer_ = new DiskBackedByteStore(tempDir, "http", MEMORY_BUFFER_SIZE);
    } catch (IOException iox) {
        throw new TTransportException(iox);
    }
}

From source file:com.evernote.android.edam.TAndroidHttpClient.java

License:Apache License

public int read(byte[] buf, int off, int len) throws TTransportException {
    if (inputStream_ == null) {
        throw new TTransportException("Response buffer is empty, no request.");
    }//from   ww  w. j  a  va 2 s  .  c o  m

    try {
        int ret = inputStream_.read(buf, off, len);
        if (ret == -1) {
            throw new TTransportException("No more data available.");
        }
        return ret;
    } catch (IOException iox) {
        throw new TTransportException(iox);
    }
}