org.apache.commons.io.output.ByteArrayOutputStream.reset()方法的使用及代码示例

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

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

ByteArrayOutputStream.reset介绍

暂无

代码示例

代码示例来源:origin: apache/incubator-gobblin

public byte[] serialize(GenericRecord record) throws IOException {
  this.outputStream.reset();
  this.writer.write(record, this.encoder);
  this.encoder.flush();
  return this.outputStream.toByteArray();
 }
}

代码示例来源:origin: commons-io/commons-io

@Test
public void testToInputStreamWithReset() throws IOException {
  //Make sure reset() do not destroy InputStream returned from toInputStream()
  final ByteArrayOutputStream baout = new ByteArrayOutputStream();
  final java.io.ByteArrayOutputStream ref = new java.io.ByteArrayOutputStream();
  //Write 8224 bytes
  writeData(baout, ref, 32);
  for(int i=0;i<128;i++) {
    writeData(baout, ref, 64);
  }
  //Get data before reset
  final InputStream in = baout.toInputStream();
  byte refData[] = ref.toByteArray();
  //Reset and write some new data
  baout.reset();
  ref.reset();
  writeData(baout, ref, new int[] { 2, 4, 8, 16 });
  //Check original data
  byte baoutData[] = IOUtils.toByteArray(in);
  assertEquals(8224, baoutData.length);
  checkByteArrays(refData, baoutData);
  //Check new data written after reset
  baoutData = IOUtils.toByteArray(baout.toInputStream());
  refData = ref.toByteArray();
  assertEquals(30, baoutData.length);
  checkByteArrays(refData, baoutData);
  baout.close();
  in.close();
}

代码示例来源:origin: commons-io/commons-io

baout.reset();
ref.reset();
baout.reset();
written = baout.write(new ByteArrayInputStream(ref.toByteArray()));
assertEquals(155, written);

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

private void newControlSequence() {
  baout.reset();
}

代码示例来源:origin: com.github.gitssie/play-transport

@Override
  public void passivateObject(PooledObject<ByteArrayOutputStream> pooledObject) {
    pooledObject.getObject().reset();
  }
},config);

代码示例来源:origin: Nextdoor/bender

@Override
public void clear() {
 this.baos.reset();
 this.cos.resetByteCount();
}

代码示例来源:origin: Nextdoor/bender

@Override
public void clear() {
 this.baos.reset();
 this.cos.resetByteCount();
}

代码示例来源:origin: ch.epfl.gsn/gsn-core

public ChartInfo ( ) {
 byteArrayOutputStream = new ByteArrayOutputStream( 64 * 1024 ); // Grows
 // as
 // needed
 byteArrayOutputStream.reset( );
 dataCollectionForTheChart = new TimeSeriesCollection( );
 rowData = "";
}

代码示例来源:origin: ch.epfl.gsn/gsn-core

/**
* Plots the chart and sends it in the form of ByteArrayOutputStream to
* outside.
* 
* @return Returns the byteArrayOutputStream.
*/
public synchronized ByteArrayOutputStream writePlot ( ) {
 if ( !changed ) return byteArrayOutputStream;
 byteArrayOutputStream.reset( );
 try {
   ChartUtilities.writeChartAsPNG( byteArrayOutputStream , chart , width , height , false , 8 );
    } catch ( IOException e ) {
   logger.warn( e.getMessage( ) , e );
 }
 return byteArrayOutputStream;
}

代码示例来源:origin: org.craftercms/crafter-commons-mongo

private void runScript(Path scriptPath) throws MongoDataException {
  String script;
  try {
    ProcessBuilder mongoProcess = new ProcessBuilder(getCommands(scriptPath));
    Process process=mongoProcess.start();
    int result=process.waitFor();
    String stdOut;
    String errOut;
    try(ByteArrayOutputStream out = new ByteArrayOutputStream()){
      IOUtils.copy(process.getInputStream(),out);
      stdOut = new String(out.toByteArray(),"UTF-8");
      out.reset();
      IOUtils.copy(process.getErrorStream(),out);
      errOut = new String(out.toByteArray(),"UTF-8");
      IOUtils.copy(process.getInputStream(),out);
    }
    if(result!=0){
      throw new IOException("Process return error \n std out:"+stdOut+"\n err out: \n"+errOut);
    }else{
     logger.debug("Process return \n std out:"+stdOut+"\n err out: \n"+errOut);
    }
  } catch (IOException | InterruptedException ex) {
    logger.error("Unable to Execute mongo Process", ex);
  }
}

代码示例来源:origin: gsvigruha/cosyan

private synchronized void log(byte event, long trxNumber) throws DBException {
 try {
  if (stream == null || !stream.getChannel().isOpen()) {
   this.stream = new FileOutputStream(
     config.journalDir() + File.separator + "transaction.journal",
     /* append= */true);
  }
  bos.reset();
  CRC32 checksum = new CRC32();
  dos.write(event);
  dos.writeLong(trxNumber);
  byte[] b = bos.toByteArray();
  checksum.update(b);
  dos.writeInt((int) checksum.getValue());
  stream.write(bos.toByteArray());
  stream.flush();
 } catch (IOException e) {
  throw new DBException(e);
 }
}

代码示例来源:origin: ch.epfl.gsn/gsn-core

public void run ( ) {
  ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream(1024*20);
  byte[] buffer = new byte[16*1024];
  BufferedInputStream content;
 while ( isActive( ) ) {
   try {
    Thread.sleep( rate );
    httpURLConnection = (HttpURLConnection) url.openConnection();
    httpURLConnection.connect();
    if ( httpURLConnection.getResponseCode() == HttpURLConnection.HTTP_ACCEPTED ) continue;
    content = new BufferedInputStream(httpURLConnection.getInputStream(),4096);
    arrayOutputStream.reset();
    int readIndex = -1;
    while ( (readIndex= content.read(buffer))!=-1)
      arrayOutputStream.write(buffer, 0, readIndex);
    postStreamElement(  arrayOutputStream.toByteArray());
   } catch ( InterruptedException e ) {
    logger.error( e.getMessage( ) , e );
   }catch (IOException e) {
    logger.error( e.getMessage( ) , e );
   }
 }
}
public String getWrapperName() {

代码示例来源:origin: ch.epfl.gsn/gsn-core

outputStream.reset( );
byte [ ] rawData = ( byte [ ] ) data.getData( "IMAGE" );
input = new ByteArrayInputStream( rawData );

代码示例来源:origin: org.apache.apex/malhar-library

public RBlockState(Algorithm compressionAlgo, FSDataInputStream fsin, BlockRegion region, Configuration conf, Reader r) throws IOException
{
 this.compressAlgo = compressionAlgo;
 Decompressor decompressor = compressionAlgo.getDecompressor();
 this.region = region;
 try {
  InputStream in = compressAlgo.createDecompressionStream(new BoundedRangeFileInputStream(fsin, region.getOffset(), region.getCompressedSize()), decompressor, DTFile.getFSInputBufferSize(conf));
  int l = 1;
  r.baos.reset();
  byte[] buf = new byte[DTFile.getFSInputBufferSize(conf)];
  while (l >= 0) {
   l = in.read(buf);
   if (l > 0) {
    r.baos.write(buf, 0, l);
   }
  }
  // keep decompressed data into cache
  byte[] blockData = r.baos.toByteArray();
  rbain = new ReusableByteArrayInputStream(blockData);
 } catch (IOException e) {
  compressAlgo.returnDecompressor(decompressor);
  throw e;
 }
}

相关文章