List of usage examples for java.io DataOutputStream writeBytes
public final void writeBytes(String s) throws IOException
From source file:com.trsst.client.MultiPartRequestEntity.java
public void writeRequest(OutputStream arg0) throws IOException { DataOutputStream out = new DataOutputStream(arg0); out.writeBytes("--" + boundary + "\r\n"); writeEntry(base, out);/*ww w .ja v a 2 s .c o m*/ out.writeBytes("--" + boundary + "\r\n"); if (content != null) { for (int i = 0; i < content.length; i++) { writeContent(content[i], contentId[i], contentType[i], out); out.writeBytes("\r\n" + "--" + boundary + "--"); } } out.flush(); }
From source file:com.dirtyunicorns.hfm.mainFragment.java
public void RunAsRoot(String string) throws IOException { Process P = Runtime.getRuntime().exec("su"); DataOutputStream os = new DataOutputStream(P.getOutputStream()); os.writeBytes(string + "\n"); os.writeBytes("exit\n"); os.flush();// w w w.j a v a 2 s. c o m }
From source file:MainFrame.CheckConnection.java
private boolean isOnline() throws MalformedURLException, IOException, Exception { String url = "http://www.itstepdeskview.hol.es"; URL obj = new URL(url); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); //add reuqest header con.setRequestMethod("POST"); con.setRequestProperty("User-Agent", "Mozilla/5.0"); con.setRequestProperty("Accept-Language", "en-US,en;q=0.5"); String urlParameters = "apideskviewer.checkStatus={}"; // Send post request con.setDoOutput(true);/* w ww. ja va 2s. c o m*/ DataOutputStream wr = new DataOutputStream(con.getOutputStream()); wr.writeBytes(urlParameters); wr.flush(); wr.close(); int responseCode = con.getResponseCode(); // System.out.println("\nSending 'POST' request to URL : " + url); // System.out.println("Post parameters : " + urlParameters); // System.out.println("Response Code : " + responseCode); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); JSONParser parser = new JSONParser(); Object parsedResponse = parser.parse(in); JSONObject jsonParsedResponse = (JSONObject) parsedResponse; String s = (String) jsonParsedResponse.get("response"); if (s.equals("online")) { return true; } else { return false; } }
From source file:org.codehaus.mojo.XUnitMojo.java
protected void preExecute(Executor exec, CommandLine commandLine, Map enviro) throws MojoExecutionException { // this//from w w w. j av a 2 s . c o m String OutputReportDir = new String(); if (reportsfileDir.isAbsolute()) { OutputReportDir = reportsfileDir.getAbsolutePath(); } else { OutputReportDir = basedir.getAbsolutePath() + "/" + reportsfileDir.getPath(); } new File(OutputReportDir).mkdirs(); getLog().info("You shall produce a xUnit report called \"" + OutputReportDir + "/xunit-result-*.xml\" within this xunit goal"); File file = new File(OutputReportDir + "/Readme.txt"); try { DataOutputStream out = new DataOutputStream(new FileOutputStream(file)); out.writeBytes( "You shall produce xUnit reports called \"xunit-result-*.xml\" within this directory.\n"); } catch (IOException e) { getLog().info("Could not write to " + OutputReportDir + "/Readme.txt"); } }
From source file:org.globusonline.transfer.DelegateProxyActivation.java
/** * Create a proxy certificate using the provided public key and signed * by the provided credential.//from www .j a va 2s. c o m * * Appends the certificate chain to proxy certificate, and returns as PEM. * Uses an external program to construct the certificate; see * https://github.com/globusonline/transfer-api-client-python/tree/master/mkproxy * @param publicKeyPem String containing a PEM encoded RSA public key * @param credentialPem String containing a PEM encoded credential, with * certificate, private key, and trust chain. * @param hours Hours the certificate will be valid for. */ public String createProxyCertificate(String publicKeyPem, String credentialPem, int hours) throws IOException, InterruptedException { Process p = new ProcessBuilder(mkproxyPath, "" + hours).start(); DataOutputStream out = new DataOutputStream(p.getOutputStream()); out.writeBytes(publicKeyPem); out.writeBytes(credentialPem); out.close(); p.waitFor(); if (p.exitValue() != 0) { InputStreamReader in = new InputStreamReader(p.getErrorStream()); String err = readEntireStream(in); throw new IOException("Returned with code " + p.exitValue() + ": " + err); } InputStreamReader in = new InputStreamReader(p.getInputStream()); String certChain = readEntireStream(in); return certChain; }
From source file:net.terryyiu.emailservice.providers.AbstractEmailServiceProvider.java
@Override public boolean send(Email email) throws IOException { HttpURLConnection connection = createConnection(); // Create a Map from an email object, which can be translated to JSON which // the specific email service provider understands. Map<String, Object> map = getRequestPostData(email); ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(map); DataOutputStream dos = new DataOutputStream(connection.getOutputStream()); dos.writeBytes(json); dos.flush();/*from ww w.j av a 2 s . co m*/ dos.close(); int responseCode = connection.getResponseCode(); System.out.println("\nSending 'POST' request to URL : " + getServiceUrl()); System.out.println("JSON: " + json); System.out.println("Response Code : " + responseCode); BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); connection.disconnect(); return false; }
From source file:org.apache.maven.plugin.cxx.XUnitMojo.java
@Override protected void preExecute(Executor exec, CommandLine commandLine, Properties enviro) throws MojoExecutionException { // this/* w w w. j a v a2 s.c om*/ String outputReportDir = new String(); if (reportsfileDir.isAbsolute()) { outputReportDir = reportsfileDir.getAbsolutePath(); } else { outputReportDir = basedir.getAbsolutePath() + "/" + reportsfileDir.getPath(); } new File(outputReportDir).mkdirs(); getLog().info("You shall produce a xUnit report called \"" + outputReportDir + File.separator + "xunit-result-*.xml\" within this xunit goal"); File file = new File(outputReportDir + "/Readme.txt"); try { DataOutputStream out = new DataOutputStream(new FileOutputStream(file)); out.writeBytes( "You shall produce xUnit reports called \"xunit-result-*.xml\" within this directory.\n"); } catch (IOException e) { getLog().info("Could not write to " + outputReportDir + File.separator + "Readme.txt"); } }
From source file:com.tonchidot.nfc_contact_exchanger.lib.PictureUploader.java
private String doFileUploadJson(String url, String fileParamName, byte[] data) { try {/*from ww w . ja v a2 s. com*/ String boundary = "BOUNDARY" + new Date().getTime() + "BOUNDARY"; String lineEnd = "\r\n"; String twoHyphens = "--"; URL connUrl = new URL(url); HttpURLConnection conn = (HttpURLConnection) connUrl.openConnection(); conn.setDoInput(true); conn.setDoOutput(true); conn.setUseCaches(false); conn.setRequestMethod("POST"); conn.setRequestProperty("Connection", "Keep-Alive"); conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary); DataOutputStream dos = new DataOutputStream(conn.getOutputStream()); dos.writeBytes(twoHyphens + boundary + lineEnd); dos.writeBytes("Content-Disposition: form-data; name=\"" + fileParamName + "\";filename=\"photo.jpg\"" + lineEnd); dos.writeBytes(lineEnd); dos.write(data, 0, data.length); dos.writeBytes(lineEnd); dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd); dos.flush(); dos.close(); BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); StringBuilder result = new StringBuilder(); String line; while ((line = rd.readLine()) != null) { result.append(line); } rd.close(); return result.toString(); } catch (IOException e) { if (Config.LOGD) { Log.d(TAG, "IOException : " + e); } } return null; }
From source file:org.aksw.gerbil.bat.annotator.AgdistisAnnotator.java
public HashSet<Annotation> getAnnotations(String textWithMentions) throws IOException, ParseException { URL agdistisUrl = new URL("http://" + host + ":" + port + "/AGDISTIS"); String parameters = "type=agdistis&text=" + URLEncoder.encode(textWithMentions, "UTF-8"); HttpURLConnection slConnection = (HttpURLConnection) agdistisUrl.openConnection(); slConnection.setDoOutput(true);//from w w w . jav a2 s. c o m slConnection.setDoInput(true); slConnection.setRequestMethod("POST"); slConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); slConnection.setRequestProperty("charset", "utf-8"); slConnection.setRequestProperty("Content-Length", "" + Integer.toString(parameters.getBytes().length)); slConnection.setUseCaches(false); DataOutputStream wr = new DataOutputStream(slConnection.getOutputStream()); wr.writeBytes(parameters); wr.flush(); wr.close(); InputStream in = slConnection.getInputStream(); HashSet<Annotation> annotations = parseJsonStream(in); return annotations; }
From source file:net.bashtech.geobot.BotManager.java
public static String postRemoteDataStrawpoll(String urlString) { String line = ""; try {//ww w . ja v a 2 s .c om HttpURLConnection c = (HttpURLConnection) (new URL("http://strawpoll.me/api/v2/polls") .openConnection()); c.setRequestMethod("POST"); c.setRequestProperty("Content-Type", "application/json"); c.setRequestProperty("User-Agent", "CB2"); c.setDoOutput(true); c.setDoInput(true); c.setUseCaches(false); String queryString = urlString; c.setRequestProperty("Content-Length", Integer.toString(queryString.length())); DataOutputStream wr = new DataOutputStream(c.getOutputStream()); wr.writeBytes(queryString); wr.flush(); wr.close(); Scanner inStream = new Scanner(c.getInputStream()); while (inStream.hasNextLine()) line += (inStream.nextLine()); inStream.close(); System.out.println(line); try { JSONParser parser = new JSONParser(); Object obj = parser.parse(line); JSONObject jsonObject = (JSONObject) obj; line = (Long) jsonObject.get("id") + ""; } catch (Exception e) { e.printStackTrace(); } } catch (MalformedURLException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } return line; }