java.io.DataOutputStream.writeBytes()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(219)

本文整理了Java中java.io.DataOutputStream.writeBytes()方法的一些代码示例,展示了DataOutputStream.writeBytes()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DataOutputStream.writeBytes()方法的具体详情如下:
包路径:java.io.DataOutputStream
类名称:DataOutputStream
方法名:writeBytes

DataOutputStream.writeBytes介绍

[英]Writes out the string to the underlying output stream as a sequence of bytes. Each character in the string is written out, in sequence, by discarding its high eight bits. If no exception is thrown, the counter written is incremented by the length of s.
[中]将字符串作为字节序列写入基础输出流。字符串中的每个字符都是通过丢弃其高8位按顺序写出的。如果未引发异常,计数器written将按s的长度递增。

代码示例

代码示例来源:origin: stackoverflow.com

DataOutputStream request = new DataOutputStream(
  httpUrlConnection.getOutputStream());

request.writeBytes(this.twoHyphens + this.boundary + this.crlf);
request.writeBytes("Content-Disposition: form-data; name=\"" +
  this.attachmentName + "\";filename=\"" + 
  this.attachmentFileName + "\"" + this.crlf);
request.writeBytes(this.crlf);

代码示例来源:origin: alibaba/mdrill

private void sendToSubprocess(String str) throws IOException {
  _processin.writeBytes(str + "\n");
  _processin.writeBytes("end\n");
  _processin.flush();
}

代码示例来源:origin: stackoverflow.com

public void RunAsRoot(String[] cmds){
      Process p = Runtime.getRuntime().exec("su");
      DataOutputStream os = new DataOutputStream(p.getOutputStream());            
      for (String tmpCmd : cmds) {
          os.writeBytes(tmpCmd+"\n");
      }           
      os.writeBytes("exit\n");  
      os.flush();
}

代码示例来源:origin: stackoverflow.com

URL url = new URL(targetURL);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", 
  "application/x-www-form-urlencoded");
DataOutputStream wr = new DataOutputStream (
  connection.getOutputStream());
wr.writeBytes(urlParameters);
wr.close();

代码示例来源:origin: stackoverflow.com

Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
String cmd = "/system/bin/input tap 100 200\n";
os.writeBytes(cmd);
os.writeBytes("exit\n");
os.flush();
os.close();
process.waitFor();

代码示例来源:origin: stackoverflow.com

DataOutputStream os = new DataOutputStream(this.socket.getOutputStream());
os.writeBytes("200");
os.close();
br.close();
socket.close();

代码示例来源:origin: testcontainers/testcontainers-java

public void callCouchbaseRestAPI(String url, String payload) throws IOException {
  String fullUrl = urlBase + url;
  @Cleanup("disconnect")
  HttpURLConnection httpConnection = (HttpURLConnection) ((new URL(fullUrl).openConnection()));
  httpConnection.setDoOutput(true);
  httpConnection.setRequestMethod("POST");
  httpConnection.setRequestProperty("Content-Type",
    "application/x-www-form-urlencoded");
  String encoded = Base64.encode((clusterUsername + ":" + clusterPassword).getBytes("UTF-8"));
  httpConnection.setRequestProperty("Authorization", "Basic " + encoded);
  @Cleanup
  DataOutputStream out = new DataOutputStream(httpConnection.getOutputStream());
  out.writeBytes(payload);
  out.flush();
  httpConnection.getResponseCode();
}

代码示例来源:origin: stackoverflow.com

try{
  Process su = Runtime.getRuntime().exec("su");
  DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());

  outputStream.writeBytes("screenrecord --time-limit 10 /sdcard/MyVideo.mp4\n");
  outputStream.flush();

  outputStream.writeBytes("exit\n");
  outputStream.flush();
  su.waitFor();
}catch(IOException e){
  throw new Exception(e);
}catch(InterruptedException e){
  throw new Exception(e);
}

代码示例来源:origin: stackoverflow.com

DataOutputStream dos = new DataOutputStream(baos);
dos.writeBytes(twoHyphens + boundary + lineEnd); 
dos.writeBytes("Content-Disposition: form-data; name=\"param1\"" + lineEnd);
dos.writeBytes("Content-Type: text/plain; charset=US-ASCII" + lineEnd);
dos.writeBytes("Content-Transfer-Encoding: 8bit" + lineEnd);
dos.writeBytes(lineEnd);
dos.writeBytes(myStringData + lineEnd);
dos.writeBytes(twoHyphens + boundary + lineEnd); 
dos.writeBytes("Content-Disposition: form-data; name=\"param3\";filename=\"test_file.dat\"" + lineEnd); 
dos.writeBytes("Content-Type: application/octet-stream" + lineEnd);
dos.writeBytes("Content-Transfer-Encoding: binary" + lineEnd);
dos.writeBytes(lineEnd); 
dos.write(buffer);
dos.writeBytes(lineEnd); 
dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd); 
dos.flush(); 
dos.close();

代码示例来源:origin: skylot/jadx

public void save(OutputStream output) throws IOException {
  try (DataOutputStream out = new DataOutputStream(output)) {
    out.writeBytes(JADX_CLS_SET_HEADER);
    out.writeByte(VERSION);
    LOG.info("Classes count: {}", classes.length);
    out.writeInt(classes.length);
    for (NClass cls : classes) {
      writeString(out, cls.getName());
    }
    for (NClass cls : classes) {
      NClass[] parents = cls.getParents();
      out.writeByte(parents.length);
      for (NClass parent : parents) {
        out.writeInt(parent.getId());
      }
    }
  }
}

代码示例来源:origin: alibaba/jstorm

private void writeString(String str) throws IOException {
  byte[] strBytes = str.getBytes("UTF-8");
  processIn.write(strBytes, 0, strBytes.length);
  processIn.writeBytes("\nend\n");
  processIn.flush();
}

代码示例来源:origin: ethereum/ethereumj

private String sendPost(String urlParams) {
  try {
    HttpURLConnection con = (HttpURLConnection) rpcUrl.openConnection();
    //add reuqest header
    con.setRequestMethod("POST");
    // Send post request
    con.setDoOutput(true);
    try (DataOutputStream wr = new DataOutputStream(con.getOutputStream())) {
      wr.writeBytes(urlParams);
      wr.flush();
    }
    int responseCode = con.getResponseCode();
    if (responseCode != 200) {
      throw new RuntimeException("HTTP Response: " + responseCode);
    }
    final StringBuffer response;
    try (BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()))) {
      String inputLine;
      response = new StringBuffer();
      while ((inputLine = in.readLine()) != null) {
        response.append(inputLine);
      }
    }
    return response.toString();
  } catch (IOException e) {
    throw new RuntimeException("Error sending POST to " + rpcUrl, e);
  }
}

代码示例来源:origin: stackoverflow.com

try {
  Process proc = Runtime.getRuntime().exec("su");
  DataOutputStream os = new DataOutputStream(proc.getOutputStream());

  os.writeBytes("service call phone 5\n");
  os.flush();

  os.writeBytes("exit\n");
  os.flush();

  if (proc.waitFor() == 255) {
    // TODO handle being declined root access
    // 255 is the standard code for being declined root for SU
  }
} catch (IOException e) {
  // TODO handle I/O going wrong
  // this probably means that the device isn't rooted
} catch (InterruptedException e) {
  // don't swallow interruptions
  Thread.currentThread().interrupt();
}

代码示例来源:origin: stackoverflow.com

public static void doCmds(List<String> cmds) throws Exception {
  Process process = Runtime.getRuntime().exec("su");
  DataOutputStream os = new DataOutputStream(process.getOutputStream());

  for (String tmpCmd : cmds) {
      os.writeBytes(tmpCmd+"\n");
  }

  os.writeBytes("exit\n");
  os.flush();
  os.close();

  process.waitFor();
}

代码示例来源:origin: stackoverflow.com

Process p = Runtime.getRuntime().exec(new String[]{"su", "-c", "system/bin/sh"});
DataOutputStream stdin = new DataOutputStream(p.getOutputStream());
//from here all commands are executed with su permissions
stdin.writeBytes("ls /data\n"); // \n executes the command
InputStream stdout = p.getInputStream();
byte[] buffer = new byte[BUFF_LEN];
int read;
String out = new String();
//read method will wait forever if there is nothing in the stream
//so we need to read it in another way than while((read=stdout.read(buffer))>0)
while(true){
  read = stdout.read(buffer);
  out += new String(buffer, 0, read);
  if(read<BUFF_LEN){
    //we have read everything
    break;
  }
}
//do something with the output

代码示例来源:origin: camunda/camunda-bpm-platform

public String writeCommand(String command, Argument args) 
  throws IOException, ProtocolException {
// assert Thread.holdsLock(this);
// can't assert because it's called from constructor
String tag = "A" + Integer.toString(tagCounter++, 10); // unique tag
output.writeBytes(tag + " " + command);

if (args != null) {
  output.write(' ');
  args.write(this);
}
output.write(CRLF);
output.flush();
return tag;
}

代码示例来源:origin: stackoverflow.com

URL url = new URL(urlString);
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
dos = new DataOutputStream(conn.getOutputStream());
dos.writeBytes(twoHyphens + boundary + lineEnd);
dos.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\"" + existingFileName + "\"" + lineEnd);
dos.writeBytes(lineEnd);
dos.writeBytes(lineEnd);
dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
dos.flush();
dos.close();

代码示例来源:origin: pentaho/pentaho-kettle

public static void appendToFile( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
 Object FunctionContext ) {
 if ( !isNull( ArgList ) && !isUndefined( ArgList ) ) {
  try {
   FileOutputStream file = new FileOutputStream( (String) ArgList[0], true );
   DataOutputStream out = new DataOutputStream( file );
   out.writeBytes( (String) ArgList[1] );
   out.flush();
   out.close();
  } catch ( Exception er ) {
   throw new RuntimeException( er.toString() );
  }
 } else {
  throw new RuntimeException( "The function call appendToFile requires arguments." );
 }
}

代码示例来源:origin: stackoverflow.com

DataOutputStream outputStream = new DataOutputStream(conn.getOutputStream());
outputStream.writeBytes(json);
outputStream.flush();
outputStream.close();

代码示例来源:origin: hierynomus/sshj

final DataOutputStream data = new DataOutputStream(out);
data.writeBytes(this.getType().toString());
data.writeBytes(headers.get("Encryption"));
data.writeBytes(headers.get("Comment"));

相关文章