Example usage for java.net SocketException printStackTrace

List of usage examples for java.net SocketException printStackTrace

Introduction

In this page you can find the example usage for java.net SocketException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:vn.mbm.phimp.me.gallery3d.picasa.PicasaApi.java

public int getAlbums(AccountManager accountManager, SyncResult syncResult, UserEntry user,
        GDataParser.EntryHandler handler) {
    // Construct the query URL for user albums.
    StringBuilder builder = new StringBuilder(BASE_URL);
    builder.append("user/");
    builder.append(Uri.encode(mAuth.user));
    builder.append(BASE_QUERY_STRING);//from   w  ww  . j  av  a2s . com
    builder.append("&kind=album");
    try {
        // Send the request.
        synchronized (mOperation) {
            GDataClient.Operation operation = mOperation;
            operation.inOutEtag = user.albumsEtag;
            boolean retry = false;
            int numRetries = 1;
            do {
                retry = false;
                synchronized (mClient) {
                    mClient.get(builder.toString(), operation);
                }
                switch (operation.outStatus) {
                case HttpStatus.SC_OK:
                    break;
                case HttpStatus.SC_NOT_MODIFIED:
                    return RESULT_NOT_MODIFIED;
                case HttpStatus.SC_FORBIDDEN:
                case HttpStatus.SC_UNAUTHORIZED:
                    if (!retry) {
                        accountManager.invalidateAuthToken(PicasaService.ACCOUNT_TYPE, mAuth.authToken);
                        retry = true;
                    }
                    if (numRetries == 0) {
                        ++syncResult.stats.numAuthExceptions;
                    }
                default:
                    Log.i(TAG, "getAlbums uri " + builder.toString());
                    Log.e(TAG, "getAlbums: unexpected status code " + operation.outStatus + " data: "
                            + operation.outBody.toString());
                    ++syncResult.stats.numIoExceptions;
                    return RESULT_ERROR;
                }
                --numRetries;
            } while (retry && numRetries >= 0);

            // Store the new ETag for the user/albums feed.
            user.albumsEtag = operation.inOutEtag;

            // Parse the response.
            synchronized (mParser) {
                GDataParser parser = mParser;
                parser.setEntry(mAlbumInstance);
                parser.setHandler(handler);
                try {
                    Xml.parse(operation.outBody, Xml.Encoding.UTF_8, parser);
                } catch (SocketException e) {
                    Log.e(TAG, "getAlbumPhotos: " + e);
                    ++syncResult.stats.numIoExceptions;
                    e.printStackTrace();
                    return RESULT_ERROR;
                }
            }
        }
        return RESULT_OK;
    } catch (IOException e) {
        Log.e(TAG, "getAlbums: " + e);
        ++syncResult.stats.numIoExceptions;
    } catch (SAXException e) {
        Log.e(TAG, "getAlbums: " + e);
        ++syncResult.stats.numParseExceptions;
    }
    return RESULT_ERROR;
}

From source file:vn.mbm.phimp.me.gallery3d.picasa.PicasaApi.java

public int getAlbumPhotos(AccountManager accountManager, SyncResult syncResult, AlbumEntry album,
        GDataParser.EntryHandler handler) {
    // Construct the query URL for user albums.
    StringBuilder builder = new StringBuilder(BASE_URL);
    builder.append("user/");
    builder.append(Uri.encode(mAuth.user));
    builder.append("/albumid/");
    builder.append(album.id);/*from   ww  w. ja  va  2s .c  om*/
    builder.append(BASE_QUERY_STRING);
    builder.append("&kind=photo");
    try {
        // Send the request.
        synchronized (mOperation) {
            GDataClient.Operation operation = mOperation;
            operation.inOutEtag = album.photosEtag;
            boolean retry = false;
            int numRetries = 1;
            do {
                retry = false;
                synchronized (mClient) {
                    mClient.get(builder.toString(), operation);
                }
                switch (operation.outStatus) {
                case HttpStatus.SC_OK:
                    break;
                case HttpStatus.SC_NOT_MODIFIED:
                    return RESULT_NOT_MODIFIED;
                case HttpStatus.SC_FORBIDDEN:
                case HttpStatus.SC_UNAUTHORIZED:
                    // We need to reset the authtoken and retry only once.
                    if (!retry) {
                        retry = true;
                        accountManager.invalidateAuthToken(PicasaService.SERVICE_NAME, mAuth.authToken);
                    }
                    if (numRetries == 0) {
                        ++syncResult.stats.numAuthExceptions;
                    }
                    break;
                default:
                    Log.e(TAG, "getAlbumPhotos: " + builder.toString() + ", unexpected status code "
                            + operation.outStatus);
                    ++syncResult.stats.numIoExceptions;
                    return RESULT_ERROR;
                }
                --numRetries;
            } while (retry && numRetries >= 0);

            // Store the new ETag for the album/photos feed.
            album.photosEtag = operation.inOutEtag;

            // Parse the response.
            synchronized (mParser) {
                GDataParser parser = mParser;
                parser.setEntry(mPhotoInstance);
                parser.setHandler(handler);
                try {
                    Xml.parse(operation.outBody, Xml.Encoding.UTF_8, parser);
                } catch (SocketException e) {
                    Log.e(TAG, "getAlbumPhotos: " + e);
                    ++syncResult.stats.numIoExceptions;
                    e.printStackTrace();
                    return RESULT_ERROR;
                }
            }
        }
        return RESULT_OK;
    } catch (IOException e) {
        Log.e(TAG, "getAlbumPhotos: " + e);
        ++syncResult.stats.numIoExceptions;
        e.printStackTrace();
    } catch (SAXException e) {
        Log.e(TAG, "getAlbumPhotos: " + e);
        ++syncResult.stats.numParseExceptions;
        e.printStackTrace();
    }
    return RESULT_ERROR;
}

From source file:com.timtory.wmgallery.picasa.PicasaApi.java

public int getAlbums(AccountManager accountManager, SyncResult syncResult, UserEntry user,
        GDataParser.EntryHandler handler) {
    // Construct the query URL for user albums.
    String baseUrl = Settings.Secure.getString(mContentResolver, SETTINGS_PICASA_GDATA_BASE_URL_KEY);
    StringBuilder builder = new StringBuilder(baseUrl != null ? baseUrl : DEFAULT_BASE_URL);
    builder.append("user/");
    builder.append(Uri.encode(mAuth.user));
    builder.append(BASE_QUERY_STRING);/*  w w  w.  j  av  a 2 s  . com*/
    builder.append("&kind=album");
    try {
        // Send the request.
        synchronized (mOperation) {
            GDataClient.Operation operation = mOperation;
            operation.inOutEtag = user.albumsEtag;
            boolean retry = false;
            int numRetries = 1;
            do {
                retry = false;
                synchronized (mClient) {
                    mClient.get(builder.toString(), operation);
                }
                switch (operation.outStatus) {
                case HttpStatus.SC_OK:
                    break;
                case HttpStatus.SC_NOT_MODIFIED:
                    return RESULT_NOT_MODIFIED;
                case HttpStatus.SC_FORBIDDEN:
                case HttpStatus.SC_UNAUTHORIZED:
                    if (!retry) {
                        accountManager.invalidateAuthToken(PicasaService.ACCOUNT_TYPE, mAuth.authToken);
                        retry = true;
                    }
                    if (numRetries == 0) {
                        ++syncResult.stats.numAuthExceptions;
                    }
                default:
                    Log.i(TAG, "getAlbums uri " + builder.toString());
                    Log.e(TAG, "getAlbums: unexpected status code " + operation.outStatus + " data: "
                            + operation.outBody.toString());
                    ++syncResult.stats.numIoExceptions;
                    return RESULT_ERROR;
                }
                --numRetries;
            } while (retry && numRetries >= 0);

            // Store the new ETag for the user/albums feed.
            user.albumsEtag = operation.inOutEtag;

            // Parse the response.
            synchronized (mParser) {
                GDataParser parser = mParser;
                parser.setEntry(mAlbumInstance);
                parser.setHandler(handler);
                try {
                    Xml.parse(operation.outBody, Xml.Encoding.UTF_8, parser);
                } catch (SocketException e) {
                    Log.e(TAG, "getAlbumPhotos: " + e);
                    ++syncResult.stats.numIoExceptions;
                    e.printStackTrace();
                    return RESULT_ERROR;
                }
            }
        }
        return RESULT_OK;
    } catch (IOException e) {
        Log.e(TAG, "getAlbums: " + e);
        ++syncResult.stats.numIoExceptions;
    } catch (SAXException e) {
        Log.e(TAG, "getAlbums: " + e);
        ++syncResult.stats.numParseExceptions;
    }
    return RESULT_ERROR;
}

From source file:com.timtory.wmgallery.picasa.PicasaApi.java

public int getAlbumPhotos(AccountManager accountManager, SyncResult syncResult, AlbumEntry album,
        GDataParser.EntryHandler handler) {
    // Construct the query URL for user albums.
    String baseUrl = Settings.Secure.getString(mContentResolver, SETTINGS_PICASA_GDATA_BASE_URL_KEY);
    StringBuilder builder = new StringBuilder(baseUrl != null ? baseUrl : DEFAULT_BASE_URL);
    builder.append("user/");
    builder.append(Uri.encode(mAuth.user));
    builder.append("/albumid/");
    builder.append(album.id);//from   w w  w .jav  a2  s  . c om
    builder.append(BASE_QUERY_STRING);
    builder.append("&kind=photo");
    try {
        // Send the request.
        synchronized (mOperation) {
            GDataClient.Operation operation = mOperation;
            operation.inOutEtag = album.photosEtag;
            boolean retry = false;
            int numRetries = 1;
            do {
                retry = false;
                synchronized (mClient) {
                    mClient.get(builder.toString(), operation);
                }
                switch (operation.outStatus) {
                case HttpStatus.SC_OK:
                    break;
                case HttpStatus.SC_NOT_MODIFIED:
                    return RESULT_NOT_MODIFIED;
                case HttpStatus.SC_FORBIDDEN:
                case HttpStatus.SC_UNAUTHORIZED:
                    // We need to reset the authtoken and retry only once.
                    if (!retry) {
                        retry = true;
                        accountManager.invalidateAuthToken(PicasaService.SERVICE_NAME, mAuth.authToken);
                    }
                    if (numRetries == 0) {
                        ++syncResult.stats.numAuthExceptions;
                    }
                    break;
                default:
                    Log.e(TAG, "getAlbumPhotos: " + builder.toString() + ", unexpected status code "
                            + operation.outStatus);
                    ++syncResult.stats.numIoExceptions;
                    return RESULT_ERROR;
                }
                --numRetries;
            } while (retry && numRetries >= 0);

            // Store the new ETag for the album/photos feed.
            album.photosEtag = operation.inOutEtag;

            // Parse the response.
            synchronized (mParser) {
                GDataParser parser = mParser;
                parser.setEntry(mPhotoInstance);
                parser.setHandler(handler);
                try {
                    Xml.parse(operation.outBody, Xml.Encoding.UTF_8, parser);
                } catch (SocketException e) {
                    Log.e(TAG, "getAlbumPhotos: " + e);
                    ++syncResult.stats.numIoExceptions;
                    e.printStackTrace();
                    return RESULT_ERROR;
                }
            }
        }
        return RESULT_OK;
    } catch (IOException e) {
        Log.e(TAG, "getAlbumPhotos: " + e);
        ++syncResult.stats.numIoExceptions;
        e.printStackTrace();
    } catch (SAXException e) {
        Log.e(TAG, "getAlbumPhotos: " + e);
        ++syncResult.stats.numParseExceptions;
        e.printStackTrace();
    }
    return RESULT_ERROR;
}

From source file:com.jagornet.dhcp.client.ClientSimulatorV6.java

/**
 * Parses the options./*from   w w w .j a  v  a 2 s  .  c  o  m*/
 * 
 * @param args the args
 * 
 * @return true, if successful
 */
protected boolean parseOptions(String[] args) {
    try {
        CommandLine cmd = parser.parse(options, args);
        if (cmd.hasOption("?")) {
            return false;
        }
        if (cmd.hasOption("n")) {
            numRequests = parseIntegerOption("num requests", cmd.getOptionValue("n"), 100);
        }
        mcastNetIf = DEFAULT_NETIF;
        if (cmd.hasOption("mi")) {
            try {
                mcastNetIf = NetworkInterface.getByName(cmd.getOptionValue("mi"));
            } catch (SocketException e) {
                e.printStackTrace();
                return false;
            }
        }
        serverAddr = DEFAULT_ADDR;
        if (cmd.hasOption("sa")) {
            serverAddr = parseIpAddressOption("server", cmd.getOptionValue("sa"), DEFAULT_ADDR);
        }
        if (cmd.hasOption("cp")) {
            clientPort = parseIntegerOption("client port", cmd.getOptionValue("cp"),
                    DhcpConstants.V6_CLIENT_PORT);
        }
        if (cmd.hasOption("sp")) {
            serverPort = parseIntegerOption("server port", cmd.getOptionValue("sp"),
                    DhcpConstants.V6_SERVER_PORT);
        }
        if (cmd.hasOption("r")) {
            rapidCommit = true;
        }
        if (cmd.hasOption("to")) {
            timeout = parseIntegerOption("timeout", cmd.getOptionValue("to"), 0);
        }
        if (cmd.hasOption("ps")) {
            poolSize = parseIntegerOption("pool size", cmd.getOptionValue("ps"), 0);
        }
    } catch (ParseException pe) {
        System.err.println("Command line option parsing failure: " + pe);
        return false;
    }
    return true;
}

From source file:net.java.jless.tls.Record.java

/**
 * Returns the fragment contained in a single Record.
 *
 * The fragment is not necessarily a message.  It may be only part of a
 * message or may be multiple messages.  In most implementations though,
 * it will be one single message.  Returns null if the connection is
 * closed or an error occurs.//from  w  ww .  ja va  2  s  .c  om
 *
 * @return  fragment
 */
public byte[] readRecord() throws TLSException {
    int recordLength = 0;
    try {
        // read header if required
        while (readBufOffset < 5) { // header is 5 bytes
            int len = ins.read(readBuf, readBufOffset, 5 - readBufOffset);
            if (len == -1) { // no more data to read
                tls.setConnected(false);
                return null;
            }
            readBufOffset += len;
        }

        // check ProtocolVersion
        if (readBuf[1] != TLSSocket.PROTOCOL_VERSION[0] || readBuf[2] != TLSSocket.PROTOCOL_VERSION[1]) {
            log("Bad Protocol Version in Record Header 0x" + Hex.b2s(readBuf, 0, 5));
            throw new TLSException("Bad Protocol Version in Record Header 0x" + Hex.b2s(readBuf, 0, 5));
        }

        // get the length
        recordLength = (readBuf[3] & 0xFF) << 8 | (readBuf[4] & 0xFF);

        // read the rest
        while (readBufOffset < recordLength + 5) {
            // try to read an extra 5 bytes here to see if more fragments ready
            int len = ins.read(readBuf, readBufOffset, recordLength + 10 - readBufOffset);
            if (len < 0) {
                throw new TLSException("Bad Record Received");
            }
            readBufOffset += len;
        }
        log("record read: (" + recordLength + ") " + Hex.b2s(readBuf, 0, 5 + recordLength));
    } catch (TLSException tlse) {
        throw tlse;
    } catch (SocketException e) { // connection closed
        e.printStackTrace();
        tls.setConnected(false);
        return null;
    } catch (IOException e) {
        e.printStackTrace();
        throw new TLSException("Error in Record.readRecord()");
    }

    byte[] fragment = new byte[recordLength];

    // decrypt if !ServerWriteCipherIsNull
    if (!serverWriteCipherIsNull) {
        try {
            decryptCipher.update(readBuf, 5, recordLength, fragment);
        } catch (Exception e) {
        }

        int fragmentLength = recordLength - macSize;
        // subtract padding from fragmentLength
        if (blockSize > 0) {
            fragmentLength -= ((fragment[recordLength - 1] & 0xff) + 1);
        }

        byte[] seqNum = l2ba(serverWriteSeqNum++);
        byte[] mac = getMAC(hmacServerWrite, seqNum, readBuf[0], fragment, 0, fragmentLength);
        log("expected mac: " + Hex.b2s(mac));

        for (int i = 0; i < mac.length; i++) {
            if (fragment[fragmentLength + i] != mac[i]) {
                log("Bad MAC received:\ndecrypted fragment with pad: " + Hex.b2s(fragment, 0, recordLength));
                throw new TLSException(
                        "Bad MAC received: decrypted fragment: " + Hex.b2s(fragment, 0, recordLength));
            }
        }

        log("mac good!");
        byte[] fragmentNoMac = new byte[fragmentLength];
        System.arraycopy(fragment, 0, fragmentNoMac, 0, fragmentLength);
        fragment = fragmentNoMac;

    } else {
        System.arraycopy(readBuf, 5, fragment, 0, recordLength);
    }

    // check ContentType
    if (readBuf[0] == CONTENTTYPE_ALERT) {
        if (fragment.length != 2) {
            throw new TLSException("Badly formed Alert message received");
        }

        if (fragment[1] != ALERT_CLOSE_NOTIFY) {
            throw new TLSException("Unsupported Alert received : 0x" + Hex.b2s(fragment));
        }

        sendMessage(CONTENTTYPE_ALERT, new byte[] { ALERT_WARNING, ALERT_CLOSE_NOTIFY });
        tls.setConnected(false);
        return null;
    }

    // reset m_readBufOffset
    // copy any extra data (like the next 5 bytes of a record header) to front of m_readBuf
    if (readBufOffset > recordLength + 5) {
        System.arraycopy(readBuf, recordLength + 5, readBuf, 0, readBufOffset - (recordLength + 5));
    }
    readBufOffset -= (recordLength + 5);

    return fragment;
}

From source file:org.squidy.nodes.tracking.CameraConfigComm.java

public void setPortIncoming(int portIncoming) {

    if (portIncoming != this.portIncoming) {
        this.portIncoming = portIncoming;
        if (oscPortIn != null) {
            oscPortIn.stopListening();/*from   w w w. j a  va 2  s .c om*/
            oscPortIn.close();
            try {
                oscPortIn = new OSCPortIn(portIncoming, endian);
            } catch (SocketException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            startConfigListener();
        }
    }
}

From source file:org.squidy.nodes.tracking.CameraConfigComm.java

public void setPortOutgoing(int portOutgoing) {

    if (portOutgoing != this.portOutgoing) {
        this.portOutgoing = portOutgoing;
        if (oscPortOut != null) {
            oscPortOut.close();//from ww w .java  2 s. com
            try {
                oscPortOut = new OSCPortOut(InetAddress.getByName(addressOutgoing), portOutgoing);
            } catch (SocketException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (UnknownHostException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}

From source file:GridFDock.DataDistribute.java

public int getFileSize(String server, String user, String pswd, String path, String filename, int port) {
    int size = 0;
    FTPFile[] ftpFile;/*w ww .j  a  va 2s .  c o  m*/
    try {
        if (ftpClient.isConnected() == false) {
            ftpClient.connect(server, port);
            ftpClient.login(user, pswd);
        }
        ftpClient.enterLocalPassiveMode();
        ftpFile = ftpClient.listFiles(path + "/" + filename);
        // FTPFile ftpFile = ftpClient.mlistFile(path+ "/" + filename);
        if (ftpFile != null) {
            // String name = ftpFile[0].getName();
            // System.out.println("test: " + ftpFile.getSize());
            size = (int) ftpFile[0].getSize();
            // String timestamp =
            // ftpFile.getTimestamp().getTime().toString();
            // String type = ftpFile.isDirectory() ? "Directory" : "File";
            // System.out.println("Name: " + name);
            // System.out.println("Size: " + size);
            // System.out.println("Type: " + type);
            // System.out.println("Timestamp: " + timestamp);
            // close ftpclient
            // ftpClient.logout();
            // ftpClient.disconnect();
        } else {
            System.out.println("The pointed file or directory may not exist!");
        }
    } catch (SocketException e) {
        System.out.println("Socket is err, can not get file size!");
        e.printStackTrace();
    } catch (IOException e) {
        System.out.println("Can not get file size!");
        e.printStackTrace();
    }
    // System.out.println("remote: " + size +" ");
    ftpFile = null;
    return size;

}

From source file:com.ocp.picasa.PicasaApi.java

public int getAlbums(AccountManager accountManager, SyncResult syncResult, UserEntry user,
        GDataParser.EntryHandler handler) {
    // Construct the query URL for user albums.
    StringBuilder builder = new StringBuilder(BASE_URL);
    builder.append("user/");
    builder.append(Uri.encode(mAuth.user));
    builder.append(BASE_QUERY_STRING);//from  w w  w  .ja v a 2  s . c om
    builder.append("&kind=album");
    try {
        // Send the request.
        synchronized (mOperation) {
            GDataClient.Operation operation = mOperation;
            operation.inOutEtag = user.albumsEtag;
            boolean retry = false;
            int numRetries = 1;
            do {
                retry = false;
                synchronized (mClient) {
                    mClient.get(builder.toString(), operation);
                }
                switch (operation.outStatus) {
                case HttpStatus.SC_OK:
                    break;
                case HttpStatus.SC_NOT_MODIFIED:
                    return RESULT_NOT_MODIFIED;
                case HttpStatus.SC_FORBIDDEN:
                case HttpStatus.SC_UNAUTHORIZED:
                    if (!retry) {
                        accountManager.invalidateAuthToken(PicasaService.ACCOUNT_TYPE, mAuth.authToken);
                        retry = true;
                    }
                    if (numRetries == 0) {
                        ++syncResult.stats.numAuthExceptions;
                    }
                default:
                    Log.i(Gallery.TAG, TAG + ": " + "getAlbums uri " + builder.toString());
                    Log.e(Gallery.TAG, TAG + ": " + "getAlbums: unexpected status code " + operation.outStatus
                            + " data: " + operation.outBody.toString());
                    ++syncResult.stats.numIoExceptions;
                    return RESULT_ERROR;
                }
                --numRetries;
            } while (retry && numRetries >= 0);

            // Store the new ETag for the user/albums feed.
            user.albumsEtag = operation.inOutEtag;

            // Parse the response.
            synchronized (mParser) {
                GDataParser parser = mParser;
                parser.setEntry(mAlbumInstance);
                parser.setHandler(handler);
                try {
                    Xml.parse(operation.outBody, Xml.Encoding.UTF_8, parser);
                } catch (SocketException e) {
                    Log.e(Gallery.TAG, TAG + ": " + "getAlbumPhotos: " + e);
                    ++syncResult.stats.numIoExceptions;
                    e.printStackTrace();
                    return RESULT_ERROR;
                }
            }
        }
        return RESULT_OK;
    } catch (IOException e) {
        Log.e(Gallery.TAG, TAG + ": " + "getAlbums: " + e);
        ++syncResult.stats.numIoExceptions;
    } catch (SAXException e) {
        Log.e(Gallery.TAG, TAG + ": " + "getAlbums: " + e);
        ++syncResult.stats.numParseExceptions;
    }
    return RESULT_ERROR;
}