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:com.orange.datavenue.client.common.ApiInvoker.java

/**
 *
 * @param in/*from ww  w  . j  a  v  a 2  s . c om*/
 * @return
 */
private String readStream(InputStream in) {
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    StringBuilder out = new StringBuilder();
    String line;
    try {
        while ((line = reader.readLine()) != null) {
            out.append(line);
        }
        reader.close();
    } catch (IOException e) {
        System.out.println(e.toString());
    }
    return out.toString();
}

From source file:edu.pitt.dbmi.facebase.hd.TrueCryptManager.java

/** "/bin/touch" TrueCrypt volume file using not the shell but FileUtils.touch()
 * Creates zero-length file/* w  w  w  .j  a  v  a  2 s.  c om*/
 * truecrypt binary requires that the file holding the truecrypt volume exists before it will create a truecrypt volume
 *
 * @return true if successful creating the file housing the truecrypt volume.
 */
public boolean touchVolume() {
    log.debug("TrueCryptManager.touchVolume() called");
    try {
        File volumeFile = new File(volume);
        FileUtils.touch(volumeFile);
    } catch (IOException ioe) {
        String errorString = "TrueCryptManager caught an ioe in touchVolume()" + ioe.toString();
        String logString = ioe.getMessage();
        edu.pitt.dbmi.facebase.hd.HumanDataController.addError(errorString, logString);
        log.error(errorString, ioe);
        return false;
    }
    return true;
}

From source file:org.f3.tools.framework.Reporter.java

private void printCombinedReport() {
    HtmlWriter combinedReport = null;/*from w  w w .  j  a va2s  . co  m*/
    try {
        combinedReport = new HtmlWriter(COMBINED_REPORT_FILE_NAME, combinedHeader());

        Set<String> kset = new TreeSet<String>(result.keySet());
        for (String x : kset) {
            // generate images and print to dashboard
            combinedReport.writeToHtmlTable(nameAsHref(x),
                    getImageRef(TIMING_RESULT_FILE_NAME, x + TIMING_GOAL_PLOT_FILE_NAME_TAIL),
                    getImageRef(TIMING_RESULT_FILE_NAME, x + TIMING_LAST_PLOT_FILE_NAME_TAIL),
                    getImageRef(FOOTPRINT_RESULT_FILE_NAME, x + FOOTPRINT_GOAL_PLOT_FILE_NAME_TAIL),
                    getImageRef(FOOTPRINT_RESULT_FILE_NAME, x + FOOTPRINT_LAST_PLOT_FILE_NAME_TAIL));
        }
    } catch (IOException ioe) {
        Utils.logger.severe(ioe.toString());
    } finally {
        Utils.close(combinedReport);
    }
}

From source file:org.zenoss.app.metric.zapp.ManagedReporter.java

String exectHostname() throws InterruptedException {
    int exit;/*from www . j av  a  2 s.  co  m*/
    String host = null;
    try {
        Process p = getProcBuilder().start();
        exit = p.waitFor();
        if (exit == 0) {
            host = new BufferedReader(new InputStreamReader(p.getInputStream())).readLine();
        } else {
            String error = new BufferedReader(new InputStreamReader(p.getErrorStream())).readLine();
            LOG.info("Could not get exec hostname -s: exit {} {}", exit, Strings.nullToEmpty(error));
        }
    } catch (IOException e) {
        LOG.info("Error getting hostname {}", e.toString());
        LOG.debug("IO error getting localhost", e);
    }
    return host;
}

From source file:info.graffy.android.websms.connector.meinbmw.ConnectorMeinBMW.java

private final StatusLine performHttpRequestForStatusLine(final String url,
        final ArrayList<BasicNameValuePair> postData) {
    try {//w ww.  j av a2 s .co  m
        final HttpResponse response = performHttpRequestForStatusLineForResponse(url, postData);
        final HttpEntity entity = response.getEntity();
        if (entity != null) {
            currentHtmlResultPage = EntityUtils.toString(entity, ENCODING);
            entity.consumeContent();
        }
        return response.getStatusLine();
    } catch (IOException e) {
        throw new WebSMSException(e.toString());
    }
}

From source file:marytts.tools.perceptiontest.PerceptionTestHttpServer.java

public void run() {
    logger.info("Starting server.");
    System.out.println("Starting server....");
    //int localPort = MaryProperties.needInteger("socket.port");
    int localPort = serverPort;

    HttpParams params = new BasicHttpParams();
    params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 0) // 0 means no timeout, any positive value means time out in miliseconds (i.e. 50000 for 50 seconds)
            .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
            .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
            .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
            .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");

    BasicHttpProcessor httpproc = new BasicHttpProcessor();
    httpproc.addInterceptor(new ResponseDate());
    httpproc.addInterceptor(new ResponseServer());
    httpproc.addInterceptor(new ResponseContent());
    httpproc.addInterceptor(new ResponseConnControl());

    BufferingHttpServiceHandler handler = new BufferingHttpServiceHandler(httpproc,
            new DefaultHttpResponseFactory(), new DefaultConnectionReuseStrategy(), params);

    // Set up request handlers
    HttpRequestHandlerRegistry registry = new HttpRequestHandlerRegistry();
    //registry.register("/perceptionTest", new FileDataRequestHandler("perception.html"));
    //registry.register("/process", new FileDataRequestHandler("perception.html"));
    //registry.register("/perceptionTest", new UtterancePlayRequestHandler());

    DataRequestHandler infoRH = new DataRequestHandler(this.testXmlName);
    UserRatingStorer userRatingRH = new UserRatingStorer(this.userRatingsDirectory, infoRH);
    registry.register("/options", infoRH);
    registry.register("/queryStatement", infoRH);
    registry.register("/process", new UtterancePlayRequestHandler(infoRH));
    registry.register("/perceptionTest", new PerceptionRequestHandler(infoRH, userRatingRH));
    registry.register("/userRating", new StoreRatingRequestHandler(infoRH, userRatingRH));
    registry.register("*", new FileDataRequestHandler());

    handler.setHandlerResolver(registry);

    // Provide an event logger
    handler.setEventListener(new EventLogger());

    IOEventDispatch ioEventDispatch = new DefaultServerIOEventDispatch(handler, params);

    //int numParallelThreads = MaryProperties.getInteger("server.http.parallelthreads", 5);
    int numParallelThreads = 5;

    logger.info("Waiting for client to connect on port " + localPort);
    System.out.println("Waiting for client to connect on port " + localPort);

    try {/*from  w  w w  .j  a  va  2  s .co m*/
        ListeningIOReactor ioReactor = new DefaultListeningIOReactor(numParallelThreads, params);
        ioReactor.listen(new InetSocketAddress(localPort));
        ioReactor.execute(ioEventDispatch);
    } catch (InterruptedIOException ex) {
        logger.info("Interrupted", ex);
        System.out.println("Interrupted" + ex.toString());
    } catch (IOException e) {
        logger.info("Problem with HTTP connection ", e);
        System.out.println("Problem with HTTP connection " + e.toString());
    }
    logger.debug("Shutdown");
    System.out.println("Shutdown");
}

From source file:com.cloudera.sqoop.testutil.ImportJobTestCase.java

/**
 * Do a MapReduce-based import of the table and verify that the results
 * were imported as expected. (tests readFields(ResultSet) and toString())
 * @param expectedVal the value we injected into the table.
 * @param importCols the columns to import. If null, all columns are used.
 *//*from   ww w  .  java2  s  . c  o  m*/
protected void verifyImport(String expectedVal, String[] importCols) {

    // paths to where our output file will wind up.
    Path tableDirPath = getTablePath();

    removeTableDir();

    Configuration conf = getConf();
    SqoopOptions opts = getSqoopOptions(conf);

    // run the tool through the normal entry-point.
    int ret;
    try {
        Sqoop importer = new Sqoop(new ImportTool(), conf, opts);
        ret = Sqoop.runSqoop(importer, getArgv(true, importCols, conf));
    } catch (Exception e) {
        LOG.error("Got exception running Sqoop: " + e.toString());
        throw new RuntimeException(e);
    }

    // expect a successful return.
    assertEquals("Failure during job", 0, ret);

    opts = getSqoopOptions(conf);
    try {
        ImportTool importTool = new ImportTool();
        opts = importTool.parseArguments(getArgv(false, importCols, conf), conf, opts, true);
    } catch (Exception e) {
        fail(e.toString());
    }

    CompilationManager compileMgr = new CompilationManager(opts);
    String jarFileName = compileMgr.getJarFilename();
    ClassLoader prevClassLoader = null;
    try {
        prevClassLoader = ClassLoaderStack.addJarFile(jarFileName, getTableName());

        // Now open and check all part-files in the table path until we find
        // a non-empty one that we can verify contains the value.
        if (!BaseSqoopTestCase.isOnPhysicalCluster()) {
            conf.set(CommonArgs.FS_DEFAULT_NAME, CommonArgs.LOCAL_FS);
        }
        FileSystem fs = FileSystem.get(conf);
        FileStatus[] stats = fs.listStatus(tableDirPath);

        if (stats == null || stats.length == 0) {
            fail("Error: no files in " + tableDirPath);
        }

        boolean foundRecord = false;
        for (FileStatus stat : stats) {
            if (!stat.getPath().getName().startsWith("part-")
                    && !stat.getPath().getName().startsWith("data-")) {
                // This isn't a data file. Ignore it.
                continue;
            }

            try {
                Object readValue = SeqFileReader.getFirstValue(stat.getPath().toString());
                LOG.info("Read back from sequencefile: " + readValue);
                foundRecord = true;
                // Add trailing '\n' to expected value since SqoopRecord.toString()
                // encodes the record delim.
                if (null == expectedVal) {
                    assertEquals("Error validating result from SeqFile", "null\n", readValue.toString());
                } else {
                    assertEquals("Error validating result from SeqFile", expectedVal + "\n",
                            readValue.toString());
                }
            } catch (EOFException eoe) {
                // EOF in a file isn't necessarily a problem. We may have some
                // empty sequence files, which will throw this. Just continue
                // in the loop.
            }
        }

        if (!foundRecord) {
            fail("Couldn't read any records from SequenceFiles");
        }
    } catch (IOException ioe) {
        fail("IOException: " + ioe.toString());
    } finally {
        if (null != prevClassLoader) {
            ClassLoaderStack.setCurrentClassLoader(prevClassLoader);
        }
    }
}

From source file:de.klemp.middleware.controller.VLCControl.java

public void connect() throws IOException {
    staticInstance = this; // used by reader to get input stream
    try {/*w w w.ja v a 2s.c o  m*/
        staticInstance.connect("localhost", VLC_PORT);
        Thread thread = new Thread(new VLCControl()); // starts the thread
                                                      // to get the text
                                                      // sent back from VLC
        thread.start();
        staticInstance.registerNotifHandler(this); // notifications call
                                                   // back to logger
        Runtime.getRuntime().addShutdownHook(new Thread() { // shutdown hook
                                                            // here makes
                                                            // sure to
                                                            // disconnect
                                                            // cleanly, as
                                                            // long as we
                                                            // are not
                                                            // terminated

            @Override
            public void run() {
                try {
                    if (isConnected()) {
                        disconnect();
                    }
                } catch (IOException ex) {
                    log.warning(ex.toString());
                }
            }
        });
    } catch (IOException e) {
        log.warning(
                "couldn't connect to VLC - you may need to start VLC with command line \"vlc --rc-host=localhost:4444\"");
        throw new IOException(e);
    }
}

From source file:edu.usf.cutr.opentripplanner.android.pois.Nominatim.java

public JSONArray requestPlaces(String paramName, String left, String top, String right, String bottom) {
    StringBuilder builder = new StringBuilder();

    String encodedParamName;//from   ww  w. j  a  va 2s .c om
    String encodedParamLeft = "";
    String encodedParamTop = "";
    String encodedParamRight = "";
    String encodedParamBottom = "";
    try {
        encodedParamName = URLEncoder.encode(paramName, OTPApp.URL_ENCODING);
        if ((left != null) && (top != null) && (right != null) && (bottom != null)) {
            encodedParamLeft = URLEncoder.encode(left, OTPApp.URL_ENCODING);
            encodedParamTop = URLEncoder.encode(top, OTPApp.URL_ENCODING);
            encodedParamRight = URLEncoder.encode(right, OTPApp.URL_ENCODING);
            encodedParamBottom = URLEncoder.encode(bottom, OTPApp.URL_ENCODING);
        }
    } catch (UnsupportedEncodingException e1) {
        Log.e(OTPApp.TAG, "Error encoding Nominatim request");
        e1.printStackTrace();
        return null;
    }

    request += "&q=" + encodedParamName;
    if ((left != null) && (top != null) && (right != null) && (bottom != null)) {
        request += "&viewbox=" + encodedParamLeft + "," + encodedParamTop + "," + encodedParamRight + ","
                + encodedParamBottom;
        request += "&bounded=1";
    }

    request += "&key=" + mApiKey;

    Log.d(OTPApp.TAG, request);

    HttpURLConnection urlConnection = null;

    try {
        URL url = new URL(request);
        urlConnection = (HttpURLConnection) url.openConnection();
        urlConnection.setConnectTimeout(OTPApp.HTTP_CONNECTION_TIMEOUT);
        urlConnection.setReadTimeout(OTPApp.HTTP_SOCKET_TIMEOUT);
        urlConnection.connect();
        int status = urlConnection.getResponseCode();

        if (status == HttpURLConnection.HTTP_OK) {
            BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
            String line;
            while ((line = reader.readLine()) != null) {
                builder.append(line);
            }
        } else {
            Log.e(OTPApp.TAG, "Error obtaining Nominatim response, status code: " + status);
        }
    } catch (IOException e) {
        e.printStackTrace();
        Log.e(OTPApp.TAG, "Error obtaining Nominatim response" + e.toString());
        return null;
    } finally {
        if (urlConnection != null) {
            urlConnection.disconnect();
        }
    }
    Log.d(OTPApp.TAG, builder.toString());

    JSONArray json = null;
    try {
        json = new JSONArray(builder.toString());
    } catch (JSONException e) {
        Log.e(OTPApp.TAG, "Error parsing Nominatim data " + e.toString());
    }

    return json;
}

From source file:ch.unizh.ini.jaer.projects.gesture.vlccontrol.VLCControl.java

public void connect() throws IOException {
    if (isConnected()) {
        log.warning("already connected");
        return;//from w  w w  . j a va 2  s  . c  o m
    }
    staticInstance = this; // used by reader to get input stream
    try {
        staticInstance.connect("localhost", VLC_PORT);
        Thread thread = new Thread(new VLCControl()); // starts the thread to get the text sent back from VLC
        thread.start();
        staticInstance.registerNotifHandler(this); // notifications call back to logger
        Runtime.getRuntime().addShutdownHook(new Thread() { // shutdown hook here makes sure to disconnect cleanly, as long as we are not terminated

            @Override
            public void run() {
                try {
                    if (isConnected()) {
                        disconnect();
                    }
                } catch (IOException ex) {
                    log.warning(ex.toString());
                }
            }
        });
    } catch (IOException e) {
        log.warning(
                "couldn't connect to VLC - you may need to start VLC with command line \"vlc --rc-host=localhost:4444\"");
        throw new IOException(e);
    }
}