Example usage for java.net SocketException getMessage

List of usage examples for java.net SocketException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.esa.nest.util.ftpUtils.java

public FTPError retrieveFile(final String remotePath, final File localFile, final Long fileSize)
        throws Exception {
    BufferedOutputStream fos = null;
    InputStream fis = null;//from ww w  . ja  v a  2  s.  c  o  m
    try {
        System.out.println("ftp retrieving " + remotePath);

        fis = ftpClient.retrieveFileStream(remotePath);
        if (fis == null) {
            final int code = ftpClient.getReplyCode();
            System.out.println("error code:" + code + " on " + remotePath);
            if (code == 550)
                return FTPError.FILE_NOT_FOUND;
            else
                return FTPError.READ_ERROR;
        }

        final File parentFolder = localFile.getParentFile();
        if (!parentFolder.exists()) {
            parentFolder.mkdirs();
        }
        fos = new BufferedOutputStream(new FileOutputStream(localFile.getAbsolutePath()));

        final StatusProgressMonitor status = new StatusProgressMonitor(fileSize,
                "Downloading " + localFile.getName() + "... ");
        status.setAllowStdOut(false);

        final int size = 4096;//32768;
        final byte[] buf = new byte[size];
        int n;
        int total = 0;
        while ((n = fis.read(buf, 0, size)) > -1) {
            fos.write(buf, 0, n);
            if (fileSize != null) {
                total += n;
                status.worked(total);
            } else {
                status.working();
            }
        }
        status.done();

        ftpClient.completePendingCommand();
        return FTPError.OK;

    } catch (SocketException e) {
        System.out.println(e.getMessage());
        connect();
        throw new SocketException(e.getMessage() + "\nPlease verify that FTP is not blocked by your firewall.");
    } catch (Exception e) {
        System.out.println(e.getMessage());
        connect();
        return FTPError.READ_ERROR;
    } finally {
        try {
            if (fis != null) {
                fis.close();
            }
            if (fos != null) {
                fos.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.l2jfree.gameserver.geoeditorcon.GeoEditorThread.java

public void sendGmPosition(int gx, int gy, short z) {
    if (!isConnected())
        return;/*  w w w. j  a  v  a2  s.c o m*/
    try {
        synchronized (_out) {
            writeC(0x0b); // length 11 bytes!
            writeC(0x01); // Cmd = save cell;
            writeD(gx); // Global coord X;
            writeD(gy); // Global coord Y;
            writeH(z); // Coord Z;
            _out.flush();
        }
    } catch (SocketException e) {
        _log.warn("GeoEditor disconnected. ", e);
        _working = false;
    } catch (Exception e) {
        _log.error(e.getMessage(), e);
        try {
            _geSocket.close();
        } catch (Exception ex) {
        }
        _working = false;
    }
}

From source file:com.singularityeye.eyetrack.MapsActivity.java

private String getHostAddress() {
    try {//from w ww .  jav  a 2 s.  c  om
        // iterate over interfaces
        for (Enumeration<NetworkInterface> networkInterfaces = NetworkInterface
                .getNetworkInterfaces(); networkInterfaces.hasMoreElements();) {
            NetworkInterface nextInterface = networkInterfaces.nextElement();
            // iterate over ip addresses (note: one interface could have more than one ip address)
            for (Enumeration<InetAddress> ipAddresses = nextInterface.getInetAddresses(); ipAddresses
                    .hasMoreElements();) {
                InetAddress nextIpAddress = ipAddresses.nextElement();
                // get an IPv4 address
                if (!nextIpAddress.isLoopbackAddress() && nextIpAddress instanceof Inet4Address) {
                    return nextIpAddress.getHostAddress(); // get first ip address
                }
            }
        }
    } catch (SocketException e) {
        Log.e("ERROR", "GetHostAddressException: " + e.getMessage());
    }
    return null;
}

From source file:nu.nethome.home.items.net.H2DatabaseTCPServer.java

public String getExternalIPAddress() {
    String result = null;/*from  w w  w. java  2  s . c  om*/
    Enumeration<NetworkInterface> interfaces2 = null;
    try {
        interfaces2 = NetworkInterface.getNetworkInterfaces();
    } catch (SocketException e) {
        logger.severe("Can't get network interfaces: " + e.getMessage());
        return "";
    }
    if (interfaces2 != null) {
        while (interfaces2.hasMoreElements() && StringUtils.isEmpty(result)) {
            NetworkInterface i = interfaces2.nextElement();
            Enumeration<InetAddress> addresses2 = i.getInetAddresses();
            while (addresses2.hasMoreElements() && (result == null || result.isEmpty())) {
                InetAddress address = addresses2.nextElement();
                if (!address.isLoopbackAddress() && address.isSiteLocalAddress()) {
                    result = address.getHostAddress();
                }
            }
        }
    }
    return result;
}

From source file:org.esa.snap.core.dataop.downloadable.FtpDownloader.java

public FTPError retrieveFile(final String remotePath, final File localFile, final Long fileSize)
        throws Exception {
    BufferedOutputStream fos = null;
    InputStream fis = null;/*from  w w w.j a  v  a  2  s. co  m*/
    try {
        SystemUtils.LOG.info("ftp retrieving " + remotePath);

        fis = ftpClient.retrieveFileStream(remotePath);
        if (fis == null) {
            final int code = ftpClient.getReplyCode();
            SystemUtils.LOG.severe("error code:" + code + " on " + remotePath);
            if (code == 550)
                return FTPError.FILE_NOT_FOUND;
            else
                return FTPError.READ_ERROR;
        }

        final File parentFolder = localFile.getParentFile();
        if (!parentFolder.exists()) {
            parentFolder.mkdirs();
        }
        fos = new BufferedOutputStream(new FileOutputStream(localFile.getAbsolutePath()));

        progressListenerList.fireProcessStarted("Downloading " + localFile.getName() + "... ", 0,
                fileSize.intValue());

        final int size = 4096;
        final byte[] buf = new byte[size];
        int n;
        int total = 0;
        while ((n = fis.read(buf, 0, size)) > -1) {
            fos.write(buf, 0, n);
            if (fileSize != null) {
                total += n;
                progressListenerList.fireProcessInProgress(total);
            }
        }
        progressListenerList.fireProcessEnded(true);

        ftpClient.completePendingCommand();
        return FTPError.OK;

    } catch (SocketException e) {
        SystemUtils.LOG.severe(e.getMessage());
        connect();
        throw new SocketException(e.getMessage() + "\nPlease verify that FTP is not blocked by your firewall.");
    } catch (Exception e) {
        SystemUtils.LOG.severe(e.getMessage());
        connect();
        return FTPError.READ_ERROR;
    } finally {
        try {
            if (fis != null) {
                fis.close();
            }
            if (fos != null) {
                fos.close();
            }
        } catch (IOException e) {
            SystemUtils.LOG.severe("Unable to close input stream " + e.getMessage());
        }
    }
}

From source file:org.apache.geode.internal.net.SocketCreator.java

public static boolean treatAsBindException(SocketException se) {
    if (se instanceof BindException) {
        return true;
    }/*from   www .ja  v  a2s .  com*/
    final String msg = se.getMessage();
    return (msg != null && msg.contains("Invalid argument: listen failed"));
}

From source file:de.pdark.dsmp.RequestHandler.java

private String readLine() throws IOException {
    if (in == null)
        in = new BufferedInputStream(clientSocket.getInputStream());

    StringBuffer buffer = new StringBuffer(256);
    int c;/*  w  w w.  j  av a2 s . c  o m*/

    try {
        while ((c = in.read()) != -1) {
            if (c == '\r')
                continue;

            if (c == '\n')
                break;

            buffer.append((char) c);
        }
    } catch (SocketException e) {
        if ("Connection reset".equals(e.getMessage()))
            return null;

        throw e;
    }

    if (c == -1)
        return null;

    if (buffer.length() == 0)
        return "";

    return buffer.toString();
}

From source file:noThreads.ParseLevel2.java

/**
 *
 * @param theUrl/*  ww w. j av  a  2  s  .c  om*/
 * @param conAttempts
 * @return
 * @throws IOException
 */
public int getResposeCode(String theUrl, int conAttempts) throws IOException {// throws IOException 
    URL newUrl = new URL(theUrl);
    //These codes are returned to indicate either fault or not.
    int ERROR_CODE = 1000, OK_CODE = 0;

    HttpURLConnection huc = (HttpURLConnection) newUrl.openConnection();
    huc.setRequestMethod("HEAD");
    huc.setRequestProperty("User-Agent", userAgent);
    huc.setReadTimeout(2000);
    huc.connect();
    try {
        return huc.getResponseCode();

    } catch (java.net.SocketException e) {
        if (e.getMessage().equalsIgnoreCase("Unexpected end of file from server")) {
            return OK_CODE; // link still valid so return a small positive int that isn't a http status code
        } else {
            return ERROR_CODE; //error, return a large int that isn't included in any http status code
        }
    } catch (java.net.SocketTimeoutException e) {
        if (e.getMessage().equalsIgnoreCase("Read timed out")) {
            if (conAttempts != MAX_CONNECTION_ATTEMPTS) {
                return getResposeCode(theUrl, conAttempts + 1);
            } else {
                return ERROR_CODE; //ERROR return a large int that isn't included in any http status code
            }
        } else {
            return ERROR_CODE;
        }

    } catch (IOException e) {
        e.printStackTrace();
        return ERROR_CODE; //error, return a large int that isn't included in any http status code      
    }
}

From source file:org.unitime.timetable.solver.remote.RemoteSolverServerProxy.java

public Object query(Object command) throws Exception {
    Socket socket = null;/*from ww w . j av a2  s .  c o  m*/
    try {
        socket = leaseConnection();
        sLog.debug("-- connection (" + iLeasedSockets.size() + ") " + this + "@" + socket.getLocalPort()
                + " leased");
        Object answer = null;
        RemoteIo.writeObject(socket, command);
        //sLog.debug("Q:"+(command instanceof Object[]?((Object[])command)[0]:command));
        try {
            answer = RemoteIo.readObject(socket);
        } catch (java.io.EOFException ex) {
        }
        ;
        //sLog.debug("A:"+answer);
        //disconnect();
        if (answer != null && answer instanceof Exception)
            throw (Exception) answer;
        return answer;
    } catch (SocketException e) {
        disconnectProxy();
        sLog.error("Unable to query, reason: " + e.getMessage());
        return null;
    } finally {
        if (socket != null) {
            releaseConnection(socket);
            sLog.debug("-- connection (" + iLeasedSockets.size() + ") " + this + "@" + socket.getLocalPort()
                    + " released");
        }
    }
}

From source file:org.moxie.proxy.connection.ProxyRequestHandler.java

private String readLine() throws IOException {
    if (in == null)
        in = new BufferedInputStream(clientSocket.getInputStream());

    StringBuilder buffer = new StringBuilder(256);
    int c;//w w w .  j  av  a  2 s  .  c om

    try {
        while ((c = in.read()) != -1) {
            if (c == '\r')
                continue;

            if (c == '\n')
                break;

            buffer.append((char) c);
        }
    } catch (SocketException e) {
        if ("connection reset".equals(e.getMessage().toLowerCase()))
            return null;

        throw e;
    }

    if (c == -1)
        return null;

    if (buffer.length() == 0)
        return "";

    return buffer.toString();
}