List of usage examples for java.io IOException toString
public String toString()
From source file:com.oracle.tutorial.jdbc.DatalinkSample.java
public static void viewTable(Connection con, Proxy proxy) throws SQLException, IOException { Statement stmt = null;//from w ww.ja v a2s . c om String query = "SELECT document_name, url FROM data_repository"; try { stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(query); if (rs.next()) { String documentName = null; java.net.URL url = null; documentName = rs.getString(1); // Retrieve the value as a URL object. url = rs.getURL(2); if (url != null) { // Retrieve the contents from the URL. URLConnection myURLConnection = url.openConnection(proxy); BufferedReader bReader = new BufferedReader( new InputStreamReader(myURLConnection.getInputStream())); System.out.println("Document name: " + documentName); String pageContent = null; while ((pageContent = bReader.readLine()) != null) { // Print the URL contents System.out.println(pageContent); } } else { System.out.println("URL is null"); } } } catch (SQLException e) { JDBCTutorialUtilities.printSQLException(e); } catch (IOException ioEx) { System.out.println("IOException caught: " + ioEx.toString()); } catch (Exception ex) { System.out.println("Unexpected exception"); ex.printStackTrace(); } finally { if (stmt != null) { stmt.close(); } } }
From source file:io.stallion.plugins.javascript.JavascriptShell.java
private static int readEvalPrint(InputStream input, OutputStream out, Context context, Global global) throws IOException, ScriptException { JsPluginSettings pluginSettings = new JsPluginSettings(); //context.eval(global, ""); //Global global = context.createGlobal(); //ScriptEnvironment env = context.getEnv(); String prompt = bundle.getString("shell.prompt"); //BufferedReader in = new BufferedReader(new InputStreamReader(input)); ConsoleReader in = new ConsoleReader(); PrintWriter err = context.getErr(); Global oldGlobal = Context.getGlobal(); boolean globalChanged = oldGlobal != global; ScriptEnvironment env = context.getEnv(); if (DB.available()) { global.put("DB", DB.instance(), false); }/*from ww w. jav a 2 s. co m*/ try { if (globalChanged) { Context.setGlobal(global); } global.addShellBuiltins(); // Load builtins global.put("javaToJsHelpers", new JavaToJsHelpers(Sandbox.allPermissions()), true); SandboxedContext ctx = new SandboxedContext(Settings.instance().getTargetFolder() + "/js", Sandbox.allPermissions(), pluginSettings); global.put("myContext", ctx, true); String stallionSharedJs = IOUtils .toString(JavascriptShell.class.getResource("/jslib/stallion_shared.js"), UTF8); context.eval(global, "load(" + JSON.stringify( map(val("script", stallionSharedJs), val("name", "stallion_shared.js"))) + ");", global, "<shellboot>"); global.put("stallionClassLoader", new UnrestrictedJsClassLoader(), true); while (true) { String source; do { //err.print(prompt); //err.flush(); source = ""; try { source = in.readLine(prompt); } catch (IOException var14) { err.println(var14.toString()); } if (source == null) { return 0; } } while (source.isEmpty()); try { Object e = context.eval(global, source, global, "<shell>"); if (e != ScriptRuntime.UNDEFINED) { err.println(JSType.toString(e)); } } catch (Exception var15) { err.println(var15); if (env._dump_on_error) { var15.printStackTrace(err); } } } } finally { if (globalChanged) { Context.setGlobal(oldGlobal); } } }
From source file:muni.fi.dp.jz.jbatch.cli.CliBatchManagerBean.java
public static String executeCommand(CommandContext ctx, ModelNode modelNode) { ModelControllerClient client = ctx.getModelControllerClient(); if (client != null) { try {//w w w . ja v a2 s. c o m ModelNode response = client.execute(modelNode); System.out.println(response); return (response.toJSONString(true)); } catch (IOException e) { System.out.println("IOException thrown when executing command: " + e.toString()); } } else { System.out.println("Connection Error! The ModelControllerClient is not available."); } return null; }
From source file:com.zivacare.android.sdk.network.NetworkUtils.java
/** * Get a handler for successful set user requests. This handler will call * the {@code onSuccess()} method of the passed {@link ZivaCareCallback} and will also * write the response to cache.// ww w . j a va2 s . co m * * @param callback * @return */ public static Response.Listener<JSONObject> getSetUserHandler(final ZivaCareCallback callback, final ZivaCareConfig mConfig) { return new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { callback.onSuccess(new ZivaCareResponse(200, response.toString())); try { mConfig.writeCacheFile(response.toString(), true); } catch (IOException e) { Log.e(LOG_TAG, e.toString()); } } }; }
From source file:com.zivacare.android.sdk.network.NetworkUtils.java
/** * Get a handler for successful delete requests. This handler will call * the {@code onSuccess()} method of the passed {@link ZivaCareCallback} and will also * clear the received ids and tokens from the current {@link ZivaCareConfig} and from the cache. * * @param callback//from ww w.ja v a 2 s. co m * @return */ public static Response.Listener<JSONObject> getDeleteUserHandler(final ZivaCareCallback callback, final ZivaCareConfig mConfig) { return new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { callback.onSuccess(new ZivaCareResponse(200, response.toString())); try { mConfig.writeCacheFile("", false); } catch (IOException e) { Log.e(LOG_TAG, e.toString()); } finally { mConfig.clean(); } } }; }
From source file:com.zivacare.android.sdk.network.NetworkUtils.java
/** * Get a handler for successful login requests. This handler will call * the {@code onSuccess()} method of the passed {@link ZivaCareCallback} and will also * save the access token in the current {@link ZivaCareConfig} and write it to cache. * * @param callback/*from www . jav a 2 s . c o m*/ * @return */ public static Response.Listener<JSONObject> getLoginHandler(final ZivaCareCallback callback, final ZivaCareConfig mConfig) { return new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { callback.onSuccess(new ZivaCareResponse(200, response.toString())); // Get access token and put it in cache mConfig.setAccessTokenFromResponse(response.toString()); try { mConfig.writeCacheFile(response.toString(), true); } catch (IOException e) { Log.e(LOG_TAG, e.toString()); } } }; }
From source file:Main.java
public static void execCmd(String szCmd, boolean bCatchLog) { try {//from ww w . j av a 2 s.c o m Log.d("PvTorrent_proc", "execCmd=" + szCmd); Runtime runtime = Runtime.getRuntime(); Process process = runtime.exec(szCmd); if (bCatchLog) { InputStream is = process.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String line = null; while (null != (line = br.readLine())) { Log.e("PvTorrent_proc", line); } } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block Log.d("PvTorrent_proc", e.toString()); } }
From source file:com.aionemu.packetsamurai.parser.valuereader.ClientStringReader.java
public static void load() { //PacketSamurai.getUserInterface().log("Loading Client strings... Please wait."); Util.drawTitle("Client Strings"); File stringsFolder = new File("./data/client_strings"); if (!stringsFolder.exists()) { stringsFolder.mkdir();/* w ww.ja va 2 s .c om*/ } try { File[] files = stringsFolder.listFiles(); File[] arrayOfFile1; int j = (arrayOfFile1 = files).length; for (int i = 0; i < j; i++) { File sFile = arrayOfFile1[i]; File xml = new File(sFile.getPath()); String stringFile = FileUtils.readFileToString(xml); String[] strings = StringUtils.substringsBetween(stringFile, "<string>", "</string>"); if (strings != null) { String[] arrayOfString1; int m = (arrayOfString1 = strings).length; for (int k = 0; k < m; k++) { String string = arrayOfString1[k]; int stringId = Integer.parseInt(StringUtils.substringBetween(string, "<id>", "</id>")); String stringBody = StringUtils.substringBetween(string, "<body>", "</body>"); stringsById.put(Integer.valueOf(stringId), stringBody); } } } PacketSamurai.getUserInterface().log( "Strings [Client] - Loaded " + stringsById.size() + " strings from " + files.length + " Files"); } catch (IOException e) { PacketSamurai.getUserInterface().log("ERROR: Failed to load client_strings.xsd: " + e.toString()); e.printStackTrace(); } }
From source file:de.hshannover.f4.trust.iron.mapserver.contentauth.RemotePDP.java
private static void runServer(int port, LocalSunXacml pdp, int threads) { Executor clientExec = Executors.newFixedThreadPool(threads); ServerSocketFactory sockFac = ServerSocketFactory.getDefault(); try {//from www.jav a 2 s . c o m ServerSocket sock = sockFac.createServerSocket(port); while (true) { Socket clientSock = sock.accept(); Runnable cmd = new HandleXacmlRequest(clientSock, pdp); System.out.println(nameDate() + "new client " + clientSock.getInetAddress()); clientExec.execute(cmd); } } catch (IOException e) { System.err.println(nameDate() + e.toString()); System.exit(1); } }
From source file:com.zivacare.android.sdk.network.NetworkUtils.java
/** * Get a handler for successful user creation requests. This handler will call * the {@code onSuccess()} method of the passed {@link ZivaCareCallback} and will also * save the received ids and token in the current {@link ZivaCareConfig} and write them to cache. * * @param callback/*from w ww . java 2s . c om*/ * @return */ public static Response.Listener<JSONObject> getCreateUserHandler(final ZivaCareCallback callback, final String clientSecret, final ZivaCareConfig mConfig) { return new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { callback.onSuccess(new ZivaCareResponse(200, response.toString())); // Get client secret and put them in cache mConfig.setClientSecret(clientSecret); try { mConfig.writeCacheFile("{\"" + ZivaCareConfig.CLIENT_SECRET + "\":\"" + clientSecret + "\"}", false); // Get special token and client data and put them in cache mConfig.setSpecialTokenFromResponse(response.toString()); mConfig.setClientIdFromResponse(response.toString()); mConfig.setClientUserIdFromResponse(response.toString()); mConfig.setClientUserNameFromResponse(response.toString()); mConfig.writeCacheFile(response.toString(), true); } catch (IOException e) { Log.e(LOG_TAG, e.toString()); } } }; }