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

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

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

DataOutputStream.flush介绍

[英]Flushes this stream to ensure all pending data is sent out to the target stream. This implementation then also flushes the target stream.
[中]刷新此流以确保将所有挂起的数据发送到目标流。然后,此实现还刷新目标流。

代码示例

代码示例来源:origin: com.h2database/h2

private void sendMessage() throws IOException {
  dataOut.flush();
  byte[] buff = outBuffer.toByteArray();
  int len = buff.length;
  dataOut = new DataOutputStream(out);
  dataOut.write(messageType);
  dataOut.writeInt(len + 4);
  dataOut.write(buff);
  dataOut.flush();
}

代码示例来源: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: alibaba/mdrill

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

代码示例来源: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

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: Dreampie/Resty

url = new URL(apiUrl + httpClientRequest.getEncodedRestPath() + "?" + httpClientRequest.getEncodedJsonParam());
 } else {
  url = new URL(apiUrl + httpClientRequest.getEncodedRestPath());
 DataOutputStream writer = new DataOutputStream(conn.getOutputStream());
 if (params != null && params.size() > 0) {
  StringBuilder builder = new StringBuilder();
   builder.append(value);
  writer.write(builder.toString().getBytes());
 writer.write(endData);
 writer.flush();
 writer.close();
} else {
url = new URL(apiUrl + httpClientRequest.getEncodedUrl());
conn = openHttpURLConnection(url, httpClientRequest, httpMethod);

代码示例来源:origin: EngineHub/WorldEdit

conn = (HttpURLConnection) reformat(url).openConnection();
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Java)");
conn.setRequestMethod(method);
conn.setUseCaches(false);
conn.setDoOutput(true);
  DataOutputStream out = new DataOutputStream(conn.getOutputStream());
  out.write(body);
  out.flush();
  out.close();

代码示例来源: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: Dreampie/Resty

/**
 * 输出参数
 *
 * @param conn
 * @param method
 * @param requestParams
 * @throws IOException
 */
private void outputParam(HttpURLConnection conn, String method, String requestParams, String encoding) throws IOException {
 //写入参数
 if (requestParams != null && !"".equals(requestParams)) {
  DataOutputStream writer = new DataOutputStream(conn.getOutputStream());
  logger.debug("Request out method " + method + ",out parameters " + requestParams);
  writer.write(requestParams.getBytes(encoding));
  writer.flush();
  writer.close();
 }
}

代码示例来源:origin: apache/hive

public static String encodeWritable(Writable key) throws IOException {
 ByteArrayOutputStream bos = new ByteArrayOutputStream();
 DataOutputStream dos = new DataOutputStream(bos);
 key.write(dos);
 dos.flush();
 return Base64.encodeBase64URLSafeString(bos.toByteArray());
}

代码示例来源:origin: google/ExoPlayer

private static void doTestSerializationV0RoundTrip(HlsDownloadAction action) throws IOException {
 ByteArrayOutputStream out = new ByteArrayOutputStream();
 DataOutputStream output = new DataOutputStream(out);
 DataOutputStream dataOutputStream = new DataOutputStream(output);
 dataOutputStream.writeUTF(action.type);
 dataOutputStream.writeInt(/* version */ 0);
 dataOutputStream.writeUTF(action.uri.toString());
 dataOutputStream.writeBoolean(action.isRemoveAction);
 dataOutputStream.writeInt(action.data.length);
 dataOutputStream.write(action.data);
 dataOutputStream.writeInt(action.keys.size());
 for (int i = 0; i < action.keys.size(); i++) {
  StreamKey key = action.keys.get(i);
  dataOutputStream.writeInt(key.groupIndex);
  dataOutputStream.writeInt(key.trackIndex);
 }
 dataOutputStream.flush();
 assertEqual(action, deserializeActionFromStream(out));
}

代码示例来源:origin: apache/hbase

@Test
public void testReads() throws Exception {
 ByteArrayOutputStream bos = new ByteArrayOutputStream(100);
 DataOutputStream dos = new DataOutputStream(bos);
 String s = "test";
 int i = 128;
 dos.write(1);
 dos.writeInt(i);
 dos.writeBytes(s);
 dos.writeLong(12345L);
 dos.writeShort(2);
 dos.flush();
 ByteBuffer bb = ByteBuffer.wrap(bos.toByteArray());

代码示例来源:origin: cymcsg/UltimateAndroid

try {
  process = Runtime.getRuntime().exec(isRoot ? COMMAND_SU : COMMAND_SH);
  os = new DataOutputStream(process.getOutputStream());
  for (String command : commands) {
    if (command == null) {
    os.write(command.getBytes());
    os.writeBytes(COMMAND_LINE_END);
    os.flush();
  os.writeBytes(COMMAND_EXIT);
  os.flush();

代码示例来源:origin: google/ExoPlayer

/** Serializes {@code action} type and data into the {@code output}. */
public static void serializeToStream(DownloadAction action, OutputStream output)
  throws IOException {
 // Don't close the stream as it closes the underlying stream too.
 DataOutputStream dataOutputStream = new DataOutputStream(output);
 dataOutputStream.writeUTF(action.type);
 dataOutputStream.writeInt(action.version);
 action.writeToStream(dataOutputStream);
 dataOutputStream.flush();
}

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

Socket socket = ...; // Create and connect the socket
DataOutputStream dOut = new DataOutputStream(socket.getOutputStream());

// Send first message
dOut.writeByte(1);
dOut.writeUTF("This is the first type of message.");
dOut.flush(); // Send off the data

// Send the second message
dOut.writeByte(2);
dOut.writeUTF("This is the second type of message.");
dOut.flush(); // Send off the data

// Send the third message
dOut.writeByte(3);
dOut.writeUTF("This is the third type of message (Part 1).");
dOut.writeUTF("This is the third type of message (Part 2).");
dOut.flush(); // Send off the data

// Send the exit message
dOut.writeByte(-1);
dOut.flush();

dOut.close();

代码示例来源:origin: wildfly/wildfly

public void sendClearPanelMsg() {
  clearPanel();
  try {
    out.reset();
    outstream=new DataOutputStream(out);
    outstream.writeInt(-13);
    channel.send(new Message(null, out.toByteArray()));
    outstream.flush();
  }
  catch(Exception ex) {
    log.error(ex.toString());
  }
}

代码示例来源:origin: apache/kylin

public static void serialize(Dictionary<?> dict, OutputStream outputStream) {
  try {
    DataOutputStream out = new DataOutputStream(outputStream);
    out.writeUTF(dict.getClass().getName());
    dict.write(out);
    out.flush();
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}

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

private static void downloadFile(String url, File outputFile) {
 try {
   URL u = new URL(url);
   URLConnection conn = u.openConnection();
   int contentLength = conn.getContentLength();

   DataInputStream stream = new DataInputStream(u.openStream());

    byte[] buffer = new byte[contentLength];
    stream.readFully(buffer);
    stream.close();

    DataOutputStream fos = new DataOutputStream(new FileOutputStream(outputFile));
    fos.write(buffer);
    fos.flush();
    fos.close();
 } catch(FileNotFoundException e) {
   return; // swallow a 404
 } catch (IOException e) {
   return; // swallow a 404
 }
}

代码示例来源:origin: wildfly/wildfly

public static byte[] createAuthenticationDigest(String passcode,long t1,double q1) throws IOException,
                                             NoSuchAlgorithmException {
  ByteArrayOutputStream baos=new ByteArrayOutputStream(512);
  DataOutputStream out=new DataOutputStream(baos);
  byte[] digest=createDigest(passcode,t1,q1);
  out.writeLong(t1);
  out.writeDouble(q1);
  out.writeInt(digest.length);
  out.write(digest);
  out.flush();
  return baos.toByteArray();
}

代码示例来源: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(lineEnd); 
dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd); 
dos.flush(); 
dos.close();

相关文章