Example usage for java.io IOException toString

List of usage examples for java.io IOException toString

Introduction

In this page you can find the example usage for java.io IOException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:org.solrsystem.Main.java

public static boolean doGetToFile(String url, String localFilePath, DownloadStatusListener listener)
        throws HttpException, IOException {
    final HttpGet request = new HttpGet(url);
    final HttpResponse resp;
    try {//www  .  j a  v  a2  s.c om
        DefaultHttpClient httpClient = new DefaultHttpClient();

        resp = httpClient.execute(request);
        long totalnum = resp.getEntity().getContentLength();
        if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
            FileOutputStream out = new FileOutputStream(localFilePath);

            InputStream inputStream = resp.getEntity().getContent();

            long bytesRead = 0;
            int bufferSize = listener.progressInterval();
            byte b[] = new byte[bufferSize];

            int cnt;
            System.out.println("reading " + bufferSize);
            while ((cnt = inputStream.read(b)) != -1) {
                out.write(b, 0, cnt);
                bytesRead += cnt;
                listener.onProgress(bytesRead, totalnum);
            }
            out.flush();
            out.close();

            //resp.getEntity().writeTo(out);

            out.close();
            return true;
        } else {
            System.out.println("Download Failed:" + resp.getStatusLine());
            return false;
        }
    } catch (final IOException e) {
        e.printStackTrace();
        throw new HttpException("IOException " + e.toString());
    }
}

From source file:com.eviware.loadui.impl.statistics.db.util.TypeConverter.java

public static byte[] imageToByteArray(BufferedImage bufferedImage) {
    if (bufferedImage != null) {
        BufferedImage image = bufferedImage;
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try {/*ww  w. j a  v  a2s  .c om*/
            ImageIO.write(image, "png", baos);
        } catch (IOException e) {
            throw new IllegalStateException(e.toString());
        }
        return baos.toByteArray();
    }
    return new byte[0];
}

From source file:Transform.java

/**
 * convert a Throwable into an array of Strings
 * @param throwable/*from   www .  j  a  v  a  2  s.  co  m*/
 * @return string representation of the throwable
 */
public static String[] getThrowableStrRep(Throwable throwable) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    throwable.printStackTrace(pw);
    pw.flush();
    LineNumberReader reader = new LineNumberReader(new StringReader(sw.toString()));
    ArrayList<String> lines = new ArrayList<String>();
    try {
        String line = reader.readLine();
        while (line != null) {
            lines.add(line);
            line = reader.readLine();
        }
    } catch (IOException ex) {
        lines.add(ex.toString());
    }
    String[] rep = new String[lines.size()];
    lines.toArray(rep);
    return rep;
}

From source file:Main.java

/** Return a <code>String</code> containing an XML file in serialized form.
 *  @param  doc  the <code>Document</code> object for the XML file to list
 *  @return (<code>String</code>) the XML file in serialized form
 *///w  w  w . jav a  2 s. com
public static String getXMLListing(Document doc) {
    // make a serializable version of the XML Document object
    // reference:  www-106.ibm.com/developerworks/xml/library/x-injava2/?dwzone=xml
    OutputFormat of = new OutputFormat(doc);
    of.setIndenting(true); // setIndenting must preceed setIndent
    of.setIndent(2);
    of.setLineSeparator(System.getProperty("line.separator"));
    // of.setPreserveSpace( true ) ;
    StringWriter sw = new StringWriter();
    // use a StringWriter instead of serializing directly to the 
    //  ObjectOutputStream because serializing directly yields a 
    //  java.io.OptionalDataException when reading the data with 
    //  ObjectInputStream.readObject()
    XMLSerializer xmlser = new XMLSerializer(sw, of);
    try {
        xmlser.serialize(doc);
    } catch (IOException ioe) {
        return "<p>IOException Error in getXMLListing( Document ):<br/>" + "&nbsp;&nbsp;&nbsp;"
                + ioe.toString();
    }

    return sw.toString();
}

From source file:com.oic.connection.Connections.java

/**
 * ????JSON??//from  w w w  .  j  ava  2s  . c  o  m
 *
 * @param json
 */
public static void broadCastMessage(JSONObject json) {
    synchronized (userConnections) {
        Session session;
        try {
            for (int i = 0; i < userConnections.size(); i++) {
                WebSocketListener websocket = userConnections.get(i);
                session = websocket.getSession();
                if (session.isOpen()) {
                    session.getRemote().sendString(json.toJSONString());
                } else {
                    session.close();
                    userConnections.remove(i);
                }
            }
        } catch (IOException e) {
            LOG.log(Level.WARNING, "error {0}", e.toString());
        }
    }
}

From source file:com.cloudera.sqoop.manager.MySQLTestUtils.java

/** @return the current username. */
public static String getCurrentUser() {
    // First, check the $USER environment variable.
    String envUser = System.getenv("USER");
    if (null != envUser) {
        return envUser;
    }/*from ww w . j ava2s . co  m*/

    // Try `whoami`
    String[] whoamiArgs = new String[1];
    whoamiArgs[0] = "whoami";
    Process p = null;
    BufferedReader r = null;
    try {
        p = Runtime.getRuntime().exec(whoamiArgs);
        InputStream is = p.getInputStream();
        r = new BufferedReader(new InputStreamReader(is));
        return r.readLine();
    } catch (IOException ioe) {
        LOG.error("IOException reading from `whoami`: " + ioe.toString());
        return null;
    } finally {
        // close our stream.
        if (null != r) {
            try {
                r.close();
            } catch (IOException ioe) {
                LOG.warn("IOException closing input stream from `whoami`: " + ioe.toString());
            }
        }

        // wait for whoami to exit.
        while (p != null) {
            try {
                int ret = p.waitFor();
                if (0 != ret) {
                    LOG.error("whoami exited with error status " + ret);
                    // suppress original return value from this method.
                    return null;
                }
            } catch (InterruptedException ie) {
                continue; // loop around.
            }
        }
    }
}

From source file:eu.digitisation.idiomaident.utils.CorpusFilter.java

private static HashSet getPosibleNames(String text) {
    HashSet<String> posibleNames = new HashSet();

    try {/*from   w  w w .j  a v  a2  s.  c om*/
        WordScanner scanner = new WordScanner(text);

        String word = "";

        while ((word = scanner.nextWord()) != null) {
            //check the first letter
            if (word.matches("\\p{Upper}+.*")) {
                posibleNames.add(word);
            }
        }

        return posibleNames;
    } catch (IOException ex) {
        System.out.println(ex.toString());
    }

    return null;
}

From source file:gov.nist.appvet.tool.sigverifier.util.FileUtil.java

public static boolean copyFile(File sourceFile, File destFile) {
    if (sourceFile == null || !sourceFile.exists() || destFile == null) {
        return false;
    }/*  w w w .j  a va  2s . c o m*/
    try {
        Files.copy(sourceFile.toPath(), destFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
    } catch (final IOException e) {
        log.error(e.toString());
        return false;
    }
    return true;
}

From source file:gov.nist.appvet.tool.sigverifier.util.FileUtil.java

public static boolean saveFileUpload(FileItem fileItem, String filePath) {
    try {//  w  ww  .j ava2s  .  com
        if (fileItem == null) {
            log.error("File item is NULL");
            return false;
        }
        File file = new File(filePath);
        fileItem.write(file);
        log.debug("Saved " + filePath);
        return true;
    } catch (IOException e) {
        log.error(e.toString());
        return false;
    } catch (Exception e) {
        log.error(e.toString());
        return false;
    }
}

From source file:ntpgraphic.PieChart.java

public static void NTPClient(String[] servers) {

    Properties defaultProps = System.getProperties(); //obtiene las "properties" del sistema
    defaultProps.put("java.net.preferIPv6Addresses", "true");//mapea el valor true en la variable java.net.preferIPv6Addresses
    if (servers.length == 0) {
        System.err.println("Usage: NTPClient <hostname-or-address-list>");
        System.exit(1);/*from   w  w  w .ja  v  a 2 s .  co  m*/
    }

    Promedio = 0;
    Cant = 0;
    int j = 1;
    NTPUDPClient client = new NTPUDPClient();
    // We want to timeout if a response takes longer than 10 seconds
    client.setDefaultTimeout(10000);
    try {
        client.open();
        for (String arg : servers) {
            System.out.println();
            try {
                InetAddress hostAddr = InetAddress.getByName(arg);
                System.out.println("> " + hostAddr.getHostName() + "/" + hostAddr.getHostAddress());
                TimeInfo info = client.getTime(hostAddr);
                processResponse(info, j++);
            } catch (IOException ioe) {
                System.err.println(ioe.toString());
            }
        }
    } catch (SocketException e) {
        System.err.println(e.toString());
    }

    client.close();
    //System.out.println("\n Pomedio "+(Promedio/Cant));
}