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

x33g5p2x  于2022-01-16 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(177)

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

BufferedOutputStream.flush介绍

[英]Flushes this stream to ensure all pending data is written out to the target stream. In addition, the target stream is flushed.
[中]刷新此流以确保将所有挂起的数据写入目标流。此外,还将刷新目标流。

代码示例

代码示例来源:origin: LaiFeng-Android/SopCastComponent

@Override
public void onData(byte[] data, int type) {
  if (mBuffer != null){
    try {
      mBuffer.write(data);
      mBuffer.flush();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}

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

public static String encodeBinaryData( byte[] val ) throws IOException {
 ByteArrayOutputStream baos = new ByteArrayOutputStream();
 GZIPOutputStream gzos = new GZIPOutputStream( baos );
 BufferedOutputStream bos = new BufferedOutputStream( gzos );
 bos.write( val );
 bos.flush();
 bos.close();
 return new String( Base64.encodeBase64( baos.toByteArray() ) );
}

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

File file = new File(Environment.getExternalStorageDirectory() + File.separator + "your_folder_on_sd", "file_name");
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
byte[] yourKey = generateKey("password");
byte[] filesBytes = encodeFile(yourKey, yourByteArrayContainigDataToEncrypt);
bos.write(fileBytes);
bos.flush();
bos.close();

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

public static Bitmap loadBitmap(String url) {
  Bitmap bitmap = null;
  InputStream in = null;
  BufferedOutputStream out = null;

  try {
    in = new BufferedInputStream(new URL(url).openStream(), IO_BUFFER_SIZE);

    final ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
    out = new BufferedOutputStream(dataStream, IO_BUFFER_SIZE);
    copy(in, out);
    out.flush();

    final byte[] data = dataStream.toByteArray();
    BitmapFactory.Options options = new BitmapFactory.Options();
    //options.inSampleSize = 1;

    bitmap = BitmapFactory.decodeByteArray(data, 0, data.length,options);
  } catch (IOException e) {
    Log.e(TAG, "Could not load Bitmap from: " + url);
  } finally {
    closeStream(in);
    closeStream(out);
  }

  return bitmap;
}

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

/**
 * Safe write on styleFile the passed inputStream
 *
 * @param in the new stream to write to styleFile
 * @param styleFile file to update
 * @throws IOException
 */
public static void writeStyle(final InputStream in, final Resource styleFile)
    throws IOException {
  try (BufferedOutputStream out = new BufferedOutputStream(styleFile.out())) {
    IOUtils.copy(in, out);
    out.flush();
  }
}

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

BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(yourFile));
bos.write(fileBytes);
bos.flush();
bos.close();

代码示例来源:origin: org.codehaus.plexus/plexus-utils

/**
 * Copy bytes from an <code>InputStream</code> to an <code>OutputStream</code>, with buffering. This is equivalent
 * to passing a {@link java.io.BufferedInputStream} and {@link java.io.BufferedOutputStream} to
 * {@link #copy(InputStream, OutputStream)}, and flushing the output stream afterwards. The streams are not closed
 * after the copy.
 * 
 * @deprecated Buffering streams is actively harmful! See the class description as to why. Use
 *             {@link #copy(InputStream, OutputStream)} instead.
 */
public static void bufferedCopy( final InputStream input, final OutputStream output )
  throws IOException
{
  final BufferedInputStream in = new BufferedInputStream( input );
  final BufferedOutputStream out = new BufferedOutputStream( output );
  copy( in, out );
  out.flush();
}

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

public static byte[] serialize(final StandardSnippet snippet) {
    try {
      final ByteArrayOutputStream baos = new ByteArrayOutputStream();
      final BufferedOutputStream bos = new BufferedOutputStream(baos);

      JAXBContext context = JAXBContext.newInstance(StandardSnippet.class);
      Marshaller marshaller = context.createMarshaller();
      marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
      marshaller.marshal(snippet, bos);

      bos.flush();
      return baos.toByteArray();
    } catch (final IOException | JAXBException e) {
      throw new FlowSerializationException(e);
    }
  }
}

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

/**
 * GZips and then base64 encodes an array of bytes to a String
 *
 * @param val
 *          the array of bytes to convert to a string
 * @return the base64 encoded string
 * @throws IOException
 *           in the case there is a Base64 or GZip encoding problem
 */
public static final String byteArrayToString( byte[] val ) throws IOException {
 String string;
 if ( val == null ) {
  string = null;
 } else {
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  GZIPOutputStream gzos = new GZIPOutputStream( baos );
  BufferedOutputStream bos = new BufferedOutputStream( gzos );
  bos.write( val );
  bos.flush();
  bos.close();
  string = new String( Base64.encodeBase64( baos.toByteArray() ) );
 }
 return string;
}

代码示例来源:origin: k9mail/k-9

private void writeLine(String s) throws IOException {
  out.write(s.getBytes());
  out.write('\r');
  out.write('\n');
  out.flush();
}

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

public static void writeStringToFile(String content, String filePath) {
 BufferedOutputStream outputStream = null;
 try {
  outputStream = new BufferedOutputStream(new FileOutputStream(getFile(filePath)));
  outputStream.write(content.getBytes());
  outputStream.flush();
 } catch (Exception e) {
  throw new ActivitiException("Couldn't write file " + filePath, e);
 } finally {
  IoUtil.closeSilently(outputStream);
 }
}

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

bos = new BufferedOutputStream( fos );
 bis = new BufferedInputStream( input );
 IOUtils.copy( bis, bos );
 bos.flush();
} catch ( Exception e ) {
 throw new KettleException( e );

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

/** Helper method which uses xstream to persist an object as xml on disk. */
void persist(XStreamPersister xp, Object obj, Resource f) throws Exception {
  BufferedOutputStream out = new BufferedOutputStream(f.out());
  xp.save(obj, out);
  out.flush();
  out.close();
}

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

/**
 * 输出状态
 * 
 * @param os
 * @throws IOException
 */
private void write(OutputStream os) throws IOException {
  BufferedOutputStream out = new BufferedOutputStream(os);
  if (Manager.instance().getSwitchFlag()) {
    out.write("running".getBytes());
  } else {
    out.write("stop".getBytes());
  }
  out.write('\r');
  out.flush();
}

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

/**
 * @param req JDBC request bytes.
 * @throws IOException On error.
 */
private void send(byte[] req) throws IOException {
  int size = req.length;
  out.write(size & 0xFF);
  out.write((size >> 8) & 0xFF);
  out.write((size >> 16) & 0xFF);
  out.write((size >> 24) & 0xFF);
  out.write(req);
  out.flush();
}

代码示例来源:origin: plutext/docx4j

private byte[] getBytesFromInputStream(InputStream is)
    throws Exception {
    BufferedInputStream bufIn = new BufferedInputStream(is);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    BufferedOutputStream bos = new BufferedOutputStream(baos);
    int c = bufIn.read();
    while (c != -1) {
      bos.write(c);
      c = bufIn.read();
    }
    bos.flush();
    baos.flush();
    //bufIn.close(); //don't do that, since it closes the ZipInputStream after we've read an entry!
    bos.close();
    return baos.toByteArray();
  }

代码示例来源:origin: frohoff/ysoserial

InputStream bufIn = is.markSupported() ? is : new BufferedInputStream(is);
BufferedOutputStream bufOut = new BufferedOutputStream(sockOut);
DataOutputStream out = new DataOutputStream(bufOut);
bufOut.flush();
out.flush();

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

private void send(DataOutputStream dout, byte[] response)
    throws IOException {
  QuorumAuthPacket authPacket;
  BufferedOutputStream bufferedOutput = new BufferedOutputStream(dout);
  BinaryOutputArchive boa = BinaryOutputArchive
      .getArchive(bufferedOutput);
  authPacket = QuorumAuth.createPacket(
      QuorumAuth.Status.IN_PROGRESS, response);
  boa.writeRecord(authPacket, QuorumAuth.QUORUM_AUTH_MESSAGE_TAG);
  bufferedOutput.flush();
}

代码示例来源:origin: plutext/docx4j

public static byte[] getBytesFromInputStream(InputStream is)
  throws Exception {
  
  BufferedInputStream bufIn = new BufferedInputStream(is);
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  BufferedOutputStream bos = new BufferedOutputStream(baos);
  int c = bufIn.read();
  while (c != -1) {
    bos.write(c);
    c = bufIn.read();
  }
  bos.flush();
  baos.flush();        
  //bufIn.close(); //don't do that, since it closes the ZipInputStream after we've read an entry!
  bos.close();
  return baos.toByteArray();
}

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

continue;
bis = new BufferedInputStream(zipFile.getInputStream(entry));
file = new Path(destDir , entry.getName());
parentFile = file.getParent();
bos = new BufferedOutputStream(fos, CACHE_SIZE);
int nRead = 0;
while ((nRead = bis.read(cache, 0, CACHE_SIZE)) != -1) {
  fos.write(cache, 0, nRead);
bos.flush();
bos.close();
fos.close();

相关文章