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

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

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

DataOutputStream.<init>介绍

[英]Constructs a new DataOutputStream on the OutputStream out. Note that data written by this stream is not in a human readable form but can be reconstructed by using a DataInputStreamon the resulting output.
[中]

代码示例

代码示例来源:origin: jenkinsci/jenkins

public Connection(InputStream in, OutputStream out) {
  this.in = in;
  this.out = out;
  this.din = new DataInputStream(in);
  this.dout = new DataOutputStream(out);
}

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

public EventMessageEncoder() {
 byteArrayOutputStream = new ByteArrayOutputStream(512);
 dataOutputStream = new DataOutputStream(byteArrayOutputStream);
}

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

ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
dos.writeLong(someLong);
dos.close();
byte[] longBytes = baos.toByteArray();

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

private static byte[] toBytecode(ClassFile cf) throws IOException {
  ByteArrayOutputStream barray = new ByteArrayOutputStream();
  DataOutputStream out = new DataOutputStream(barray);
  try {
    cf.write(out);
  }
  finally {
    out.close();
  }
  return barray.toByteArray();
}

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

protected final void send(Op op, String text) throws IOException {
  ByteArrayOutputStream buf = new ByteArrayOutputStream();
  new DataOutputStream(buf).writeUTF(text);
  send(op, buf.toByteArray());
}

代码示例来源: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());
 bbis.close();
 bb = ByteBuffer.wrap(bos.toByteArray());
 bbis = new ByteBuffInputStream(new MultiByteBuff(bb));
 DataInputStream dis = new DataInputStream(bbis);
 dis.read();
 assertEquals(i, dis.readInt());

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

String boundary =  "RQdzAAihJq7Xp1kjraqf"; 
ByteArrayOutputStream baos = new ByteArrayOutputStream();
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();
ByteArrayInputStream content = new ByteArrayInputStream(baos.toByteArray());
BasicHttpEntity entity = new BasicHttpEntity();
entity.setContent(content);

代码示例来源: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();
 writer.flush();
 writer.close();
} else {
 outputParam(conn, httpMethod, httpClientRequest.getEncodedParams(), httpClientRequest.getEncoding());
url = new URL(apiUrl + httpClientRequest.getEncodedUrl());
conn = openHttpURLConnection(url, httpClientRequest, httpMethod);

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

public boolean save(String fileName)
{
  DataOutputStream out;
  try
  {
    out = new DataOutputStream(new BufferedOutputStream(IOUtil.newOutputStream(fileName)));
    out.writeInt(size);
    for (int i = 0; i < size; i++)
    {
      out.writeInt(base[i]);
      out.writeInt(check[i]);
    }
    out.close();
  }
  catch (Exception e)
  {
    return false;
  }
  return true;
}

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

/**
 * 保存到路径
 *
 * @param modelFile
 * @throws IOException
 */
public void save(String modelFile) throws IOException
{
  DataOutputStream out = new DataOutputStream(new BufferedOutputStream(IOUtil.newOutputStream(modelFile)));
  save(out);
  out.close();
}

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

/**
 * Encodes a built DateTimeZone to the given stream. Call readFrom to
 * decode the data into a DateTimeZone object.
 *
 * @param out  the output stream to receive the encoded DateTimeZone
 * @since 1.5 (parameter added)
 */
public void writeTo(String zoneID, OutputStream out) throws IOException {
  if (out instanceof DataOutput) {
    writeTo(zoneID, (DataOutput)out);
  } else {
    DataOutputStream dout = new DataOutputStream(out);
    writeTo(zoneID, (DataOutput)dout);
    dout.flush();
  }
}

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

private FileInputSplit createTempDeflateFile(String content) throws IOException {
  File tempFile = File.createTempFile("test_contents", "tmp.deflate");
  tempFile.deleteOnExit();
  DataOutputStream dos = new DataOutputStream(new DeflaterOutputStream(new FileOutputStream(tempFile)));
  dos.writeBytes(content);
  dos.close();
  return new FileInputSplit(0, new Path(tempFile.toURI().toString()), 0, tempFile.length(), new String[] {"localhost"});
}

代码示例来源: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: aws/aws-sdk-java

private byte[] getPrelude(int totalLength) throws IOException {
  ByteArrayOutputStream baos = new ByteArrayOutputStream(8);
  DataOutputStream dos = new DataOutputStream(baos);
  int headerLength = totalLength - Message.MESSAGE_OVERHEAD - payload.length;
  dos.writeInt(totalLength);
  dos.writeInt(headerLength);
  dos.close();
  return baos.toByteArray();
}

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

相关文章