List of usage examples for java.io DataOutputStream writeBytes
public final void writeBytes(String s) throws IOException
From source file:org.apache.hadoop.mapred.TestJobSummary.java
private static void createInput(Path inDir, Configuration conf) throws IOException { String input = "Hadoop is framework for data intensive distributed " + "applications.\n" + "Hadoop enables applications to work with thousands of nodes."; FileSystem fs = inDir.getFileSystem(conf); if (!fs.mkdirs(inDir)) { throw new IOException("Failed to create the input directory:" + inDir.toString()); }//w w w .j a va 2s.c om fs.setPermission(inDir, new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.ALL)); DataOutputStream file = fs.create(new Path(inDir, "data.txt")); int i = 0; while (i < 2) { file.writeBytes(input); i++; } file.close(); }
From source file:Main.java
public static String RunExecCmd(StringBuilder sb, Boolean su) { String shell;/* w w w . j a v a 2 s . co m*/ if (su) { shell = "su"; } else { shell = "sh"; } Process process = null; DataOutputStream processOutput = null; InputStream processInput = null; String outmsg = new String(); try { process = Runtime.getRuntime().exec(shell); processOutput = new DataOutputStream(process.getOutputStream()); processOutput.writeBytes(sb.toString() + "\n"); processOutput.writeBytes("exit\n"); processOutput.flush(); processInput = process.getInputStream(); outmsg = inputStream2String(processInput, "UTF-8"); process.waitFor(); } catch (Exception e) { //Log.d("*** DEBUG ***", "ROOT REE" + e.getMessage()); //return; } finally { try { if (processOutput != null) { processOutput.close(); } process.destroy(); } catch (Exception e) { } } return outmsg; }
From source file:ke.co.tawi.babblesms.server.servlet.accountmngmt.Login.java
public static boolean validateCaptcha(String gRecaptchaResponse) throws IOException { if (gRecaptchaResponse == null || "".equals(gRecaptchaResponse)) { return false; }//from w w w . j a va2s . co m try { URL obj = new URL(url); HttpsURLConnection con = (HttpsURLConnection) obj.openConnection(); // add reuqest header con.setRequestMethod("POST"); con.setRequestProperty("User-Agent", USER_AGENT); con.setRequestProperty("Accept-Language", "en-US,en;q=0.5"); String postParams = "secret=" + secret + "&response=" + gRecaptchaResponse; // Send post request con.setDoOutput(true); DataOutputStream wr = new DataOutputStream(con.getOutputStream()); wr.writeBytes(postParams); wr.flush(); wr.close(); int responseCode = con.getResponseCode(); System.out.println("\nSending 'POST' request to URL : " + url); System.out.println("Post parameters : " + postParams); System.out.println("Response Code : " + responseCode); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); // print result System.out.println(response.toString()); //parse JSON response and return 'success' value JsonReader jsonReader = Json.createReader(new StringReader(response.toString())); JsonObject jsonObject = jsonReader.readObject(); jsonReader.close(); return jsonObject.getBoolean("success"); } catch (Exception e) { e.printStackTrace(); return false; } }
From source file:org.apache.hadoop.mapred.TestChildsKillingOfMemoryExceedsTask.java
private static void createInput(Path inDir, Configuration conf) throws IOException { String input = "Hadoop is framework for data intensive distributed " + "applications.\nHadoop enables applications to" + " work with thousands of nodes."; FileSystem fs = inDir.getFileSystem(conf); if (!fs.mkdirs(inDir)) { throw new IOException("Failed to create the input directory:" + inDir.toString()); }//from w w w . j ava 2s.com fs.setPermission(inDir, new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.ALL)); DataOutputStream file = fs.create(new Path(inDir, "data.txt")); file.writeBytes(input); file.close(); }
From source file:org.apache.hadoop.mapred.TestJobCleanup.java
@BeforeClass public static void setUp() throws IOException { JobConf conf = new JobConf(); fileSys = FileSystem.get(conf); fileSys.delete(new Path(TEST_ROOT_DIR), true); conf.set("mapred.job.tracker.handler.count", "1"); conf.set("mapred.job.tracker", "127.0.0.1:0"); conf.set("mapred.job.tracker.http.address", "127.0.0.1:0"); conf.set("mapred.task.tracker.http.address", "127.0.0.1:0"); conf.set(JHAdminConfig.MR_HISTORY_INTERMEDIATE_DONE_DIR, TEST_ROOT_DIR + "/intermediate"); conf.set(org.apache.hadoop.mapreduce.lib.output.FileOutputCommitter.SUCCESSFUL_JOB_OUTPUT_DIR_MARKER, "true"); mr = new MiniMRCluster(1, "file:///", 1, null, null, conf); inDir = new Path(TEST_ROOT_DIR, "test-input"); String input = "The quick brown fox\n" + "has many silly\n" + "red fox sox\n"; DataOutputStream file = fileSys.create(new Path(inDir, "part-" + 0)); file.writeBytes(input); file.close();// w ww .java 2 s . c o m emptyInDir = new Path(TEST_ROOT_DIR, "empty-input"); fileSys.mkdirs(emptyInDir); }
From source file:org.apache.hadoop.mapreduce.MapReduceTestUtil.java
public static Job createJob(Configuration conf, Path inDir, Path outDir, int numInputFiles, int numReds, String input) throws IOException { Job job = new Job(conf); FileSystem fs = FileSystem.get(conf); if (fs.exists(outDir)) { fs.delete(outDir, true);/* ww w . j a va2s . c om*/ } if (fs.exists(inDir)) { fs.delete(inDir, true); } fs.mkdirs(inDir); for (int i = 0; i < numInputFiles; ++i) { DataOutputStream file = fs.create(new Path(inDir, "part-" + i)); file.writeBytes(input); file.close(); } FileInputFormat.setInputPaths(job, inDir); FileOutputFormat.setOutputPath(job, outDir); job.setNumReduceTasks(numReds); return job; }
From source file:org.apache.hadoop.mapred.TestCacheFileReferenceCount.java
private static URI createCacheFile(Path tmpFolderPath, String cacheFile) throws IOException { String input = "distribute cache content..."; FileSystem dfs = jobClient.getFs(); conf = wovenClient.getDaemonConf();//from w w w . j a v a 2 s . c o m FileSystem fs = tmpFolderPath.getFileSystem(conf); if (!fs.mkdirs(tmpFolderPath)) { throw new IOException("Failed to create the temp directory:" + tmpFolderPath.toString()); } deleteCacheFile(new Path(tmpFolderPath, cacheFile)); DataOutputStream file = fs.create(new Path(tmpFolderPath, cacheFile)); int i = 0; while (i++ < 100) { file.writeBytes(input); } file.close(); dfs.setPermission(new Path(tmpFolderPath, cacheFile), new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.ALL)); URI uri = URI.create(new Path(tmpFolderPath, cacheFile).toString()); return uri; }
From source file:com.chintans.venturebox.util.Utils.java
public static String exec(String command) { try {/*from w ww.j ava 2s.co m*/ Process p = Runtime.getRuntime().exec(command); DataOutputStream os = new DataOutputStream(p.getOutputStream()); os.writeBytes("sync\n"); os.writeBytes("exit\n"); os.flush(); p.waitFor(); return getStreamLines(p.getInputStream()); } catch (Exception ex) { ex.printStackTrace(); return null; } }
From source file:Main.java
public static String sudoForResult(String... strings) { String res = ""; DataOutputStream outputStream = null; InputStream response = null;//from ww w . j a v a2s . com try { Process su = Runtime.getRuntime().exec("su"); outputStream = new DataOutputStream(su.getOutputStream()); response = su.getInputStream(); for (String s : strings) { outputStream.writeBytes(s + "\n"); outputStream.flush(); } outputStream.writeBytes("exit\n"); outputStream.flush(); try { su.waitFor(); } catch (InterruptedException e) { e.printStackTrace(); } res = readFully(response); } catch (IOException e) { e.printStackTrace(); } finally { closeSilently(outputStream, response); } return res; }
From source file:org.wso2.carbon.automation.test.utils.http.client.HttpsURLConnectionClient.java
public static HttpsResponse postWithBasicAuth(String uri, String requestQuery, String contentType, String userName, String password) throws IOException { if (uri.startsWith("https://")) { URL url = new URL(uri); HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(); conn.setRequestMethod("POST"); String encode = new String( new org.apache.commons.codec.binary.Base64().encode((userName + ":" + password).getBytes())) .replaceAll("\n", ""); conn.setRequestProperty("Authorization", "Basic " + encode); conn.setDoOutput(true); // Triggers POST. conn.setRequestProperty("Content-Type", contentType); conn.setRequestProperty("charset", "utf-8"); conn.setRequestProperty("Content-Length", "" + Integer.toString(requestQuery.getBytes().length)); conn.setUseCaches(false);//from w ww .j ava 2s . c o m conn.setHostnameVerifier(new HostnameVerifier() { public boolean verify(String hostname, SSLSession session) { return true; } }); DataOutputStream wr = new DataOutputStream(conn.getOutputStream()); wr.writeBytes(requestQuery); conn.setReadTimeout(10000); conn.connect(); System.out.println(conn.getRequestMethod()); // Get the response StringBuilder sb = new StringBuilder(); BufferedReader rd = null; try { rd = new BufferedReader(new InputStreamReader(conn.getInputStream(), Charset.defaultCharset())); String line; while ((line = rd.readLine()) != null) { sb.append(line); } } catch (FileNotFoundException ignored) { } finally { if (rd != null) { rd.close(); } wr.flush(); wr.close(); conn.disconnect(); } return new HttpsResponse(sb.toString(), conn.getResponseCode()); } return null; }