當前位置: 首頁>>代碼示例>>Java>>正文


Java ByteArrayOutputStream.writeTo方法代碼示例

本文整理匯總了Java中java.io.ByteArrayOutputStream.writeTo方法的典型用法代碼示例。如果您正苦於以下問題:Java ByteArrayOutputStream.writeTo方法的具體用法?Java ByteArrayOutputStream.writeTo怎麽用?Java ByteArrayOutputStream.writeTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.io.ByteArrayOutputStream的用法示例。


在下文中一共展示了ByteArrayOutputStream.writeTo方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: writeToResponse

import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
/**
 * Write the given temporary OutputStream to the HTTP response.
 * @param response current HTTP response
 * @param baos the temporary OutputStream to write
 * @throws IOException if writing/flushing failed
 */
protected void writeToResponse(HttpServletResponse response, ByteArrayOutputStream baos) throws IOException {
    // Write content type and also length (determined via byte array).
    response.setContentType(getContentType());
    response.setContentLength(baos.size());

    // Flush byte array to servlet output stream.
    ServletOutputStream out = response.getOutputStream();
    baos.writeTo(out);
    out.flush();
}
 
開發者ID:devefx,項目名稱:validator-web,代碼行數:17,代碼來源:AbstractView.java

示例2: jsGet_body

import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
public Object jsGet_body() {
    ByteArrayOutputStream body = javaContext.getBodyStream();
    if (body == null) {
        return Context.getUndefinedValue();
    }
    final Scriptable buffer = cx.newObject(scope, "Uint8Array");
    try {
        body.writeTo(new OutputStream() {
            int count = 0;

            @Override
            public void write(int b) throws IOException {
                buffer.put(count++, buffer, b);
            }
        });
    } catch (Exception e) {
        return e;
    }
    return buffer;
}
 
開發者ID:baidu,項目名稱:openrasp,代碼行數:21,代碼來源:JSRequestContext.java

示例3: encodeKeyValues

import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
static ByteBuffer encodeKeyValues(DataBlockEncoding encoding, List<KeyValue> kvs,
    HFileBlockEncodingContext encodingContext) throws IOException {
  DataBlockEncoder encoder = encoding.getEncoder();
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  baos.write(HConstants.HFILEBLOCK_DUMMY_HEADER);
  DataOutputStream dos = new DataOutputStream(baos);
  encoder.startBlockEncoding(encodingContext, dos);
  for (KeyValue kv : kvs) {
    encoder.encode(kv, encodingContext, dos);
  }
  BufferGrabbingByteArrayOutputStream stream = new BufferGrabbingByteArrayOutputStream();
  baos.writeTo(stream);
  encoder.endBlockEncoding(encodingContext, dos, stream.getBuffer());
  byte[] encodedData = new byte[baos.size() - ENCODED_DATA_OFFSET];
  System.arraycopy(baos.toByteArray(), ENCODED_DATA_OFFSET, encodedData, 0, encodedData.length);
  return ByteBuffer.wrap(encodedData);
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:18,代碼來源:TestDataBlockEncoders.java

示例4: export

import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
protected void export(GeoSet geoSet, OutputStream outputStream) throws IOException {
    
    this.recordCounter = 1;
    this.shxRecords.clear();
    
    // Accumulate the data in a ByteArrayOutputStream.
    // This allows for finding the size of the resulting file.
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    BufferedOutputStream buffOs = new BufferedOutputStream(byteArrayOutputStream);
    MixedEndianDataOutputStream geom = new MixedEndianDataOutputStream(buffOs);
    this.writeGeoSet(geom, geoSet);
    // add total size of geometry to shx records
    this.shxRecords.add(new Integer(geom.size()));
    
    // Close the ByteArrayOutputStream.
    // This is not closing the destination outputStream
    geom.close();
    
    // write file header
    MixedEndianDataOutputStream head = new MixedEndianDataOutputStream(outputStream);
    this.writeHeader(geoSet, head, geom.size());
    
    // copy the geometry to the outputStream
    byteArrayOutputStream.writeTo(outputStream);
}
 
開發者ID:berniejenny,項目名稱:MapAnalyst,代碼行數:26,代碼來源:ShapeGeometryExporter.java

示例5: writeSection

import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
/**
 * Write a section with header and data.
 * 
 * @param type
 *            the name of the section
 * @param data
 *            the data of the section
 * @param name
 *            the name, must be set if the id == 0
 * @throws IOException
 *             if any I/O error occur
 */
void writeSection( SectionType type, WasmOutputStream data, String name ) throws IOException {
    ByteArrayOutputStream baos = (ByteArrayOutputStream)data.out;
    int size = baos.size();
    if( size == 0 ) {
        return;
    }
    writeVaruint32( type.ordinal() );
    writeVaruint32( size );
    if( type == SectionType.Custom ) {
        byte[] bytes = name.getBytes( StandardCharsets.ISO_8859_1 );
        writeVaruint32( bytes.length );
        write( bytes );
    }
    baos.writeTo( this );
}
 
開發者ID:i-net-software,項目名稱:JWebAssembly,代碼行數:28,代碼來源:WasmOutputStream.java

示例6: getServlet

import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
@Override
public HttpHandler getServlet() {
    return exchange -> {
        final ByteArrayOutputStream response = new ByteArrayOutputStream(1 << 20);
        final OutputStreamWriter osw = new OutputStreamWriter(response);
        TextFormat.write004(osw, registry.metricFamilySamples());
        osw.flush();
        osw.close();
        response.flush();
        response.close();

        exchange.getResponseHeaders().set("Content-Type", TextFormat.CONTENT_TYPE_004);
        exchange.getResponseHeaders().set("Content-Length", String.valueOf(response.size()));
        exchange.sendResponseHeaders(200, response.size());
        response.writeTo(exchange.getResponseBody());
        exchange.close();
    };
}
 
開發者ID:secondbase,項目名稱:secondbase,代碼行數:19,代碼來源:PrometheusWebConsole.java

示例7: saveFile

import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
/**
 * 保存文件
 *
 * @param baos
 * @param fileName
 * @throws Exception
 */
public static String saveFile(ByteArrayOutputStream baos, String fileName)
        throws Exception {
    String Path = App.getAppContext().getFilesDir().getPath();
    File dirFile = new File(Path);
    if (!dirFile.exists()) {
        dirFile.mkdir();
    }
    File myCaptureFile = new File(Path + "/" + fileName);
    FileOutputStream fi = new FileOutputStream(myCaptureFile);
    baos.writeTo(fi);
    baos.flush();
    baos.close();
    return myCaptureFile.getAbsolutePath();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:22,代碼來源:BaseUtils.java

示例8: getBytes

import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
/**
 * <p>解析報文協議,返回字節數組,用於應用間的消息的傳輸</p>
 * @Title: getBytes
 * @Description: 解析報文協議,返回字節數組,用於應用間的消息的傳輸
 * @return byte[] 用於傳輸的報文包
 * @author [email protected]
 * @date 2017年3月24日 上午11:13:39
 */
public byte[] getBytes(){
	//結果返回數據內容
	byte[] resultContent = new byte[0];
	try{
		//創建一個不用關閉的輸出流,用於最後的byte[]轉換,不用維護數組的pos
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		//寫入tpdu
		baos.write(getTpduBytes());
		//寫入header
		baos.write(getHeaderBytes());
		//寫入mti+bitmap+8583報文數據(設置有校驗位,則包含,沒設置校驗位,則不包含)
		baos.write(getMacBlock());
		//寫入校驗域
		baos.write(getMac());
		//計算報文整體長度
		String size = StringUtil.repeat("00", factory.getMsgLength())+Integer.toHexString(baos.size());
		size = size.substring(size.length() - factory.getMsgLength() * 2);
		byte[] bSize = EncodeUtil.bcd(size);
		//準備最終報文數據
		ByteArrayOutputStream resultStream = new ByteArrayOutputStream();
		//寫入報文長度
		resultStream.write(bSize);
		//寫入報文信息
		baos.writeTo(resultStream);
		resultContent = resultStream.toByteArray();
	}catch(IOException e){
		e.printStackTrace();
	}
	return resultContent;
}
 
開發者ID:Ajsgn,項目名稱:Java8583,代碼行數:39,代碼來源:Iso8583Message.java

示例9: compressQuality

import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
private void compressQuality(File outFile, long maxSize, int maxQuality) throws IOException {
    long length = outFile.length();
    int quality = 90;
    if (length > maxSize) {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        BoxingLog.d("source file size : " + outFile.length() + ",path : " + outFile);
        while (true) {
            compressPhotoByQuality(outFile, bos, quality);
            long size = bos.size();
            BoxingLog.d("compressed file size : " + size);
            if (quality <= maxQuality) {
                break;
            }
            if (size < maxSize) {
                break;
            } else {
                quality -= 10;
                bos.reset();
            }
        }
        OutputStream fos = new FileOutputStream(outFile);
        bos.writeTo(fos);
        bos.flush();
        fos.close();
        bos.close();
    }
}
 
開發者ID:Bilibili,項目名稱:boxing,代碼行數:28,代碼來源:ImageCompressor.java

示例10: serializeAsPB

import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
/**
 * Write trailer data as protobuf
 * @param outputStream
 * @throws IOException
 */
void serializeAsPB(DataOutputStream output) throws IOException {
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  HFileProtos.FileTrailerProto.Builder builder = HFileProtos.FileTrailerProto.newBuilder()
    .setFileInfoOffset(fileInfoOffset)
    .setLoadOnOpenDataOffset(loadOnOpenDataOffset)
    .setUncompressedDataIndexSize(uncompressedDataIndexSize)
    .setTotalUncompressedBytes(totalUncompressedBytes)
    .setDataIndexCount(dataIndexCount)
    .setMetaIndexCount(metaIndexCount)
    .setEntryCount(entryCount)
    .setNumDataIndexLevels(numDataIndexLevels)
    .setFirstDataBlockOffset(firstDataBlockOffset)
    .setLastDataBlockOffset(lastDataBlockOffset)
    // TODO this is a classname encoded into an  HFile's trailer. We are going to need to have 
    // some compat code here.
    .setComparatorClassName(comparatorClassName)
    .setCompressionCodec(compressionCodec.ordinal());
  if (encryptionKey != null) {
    builder.setEncryptionKey(ByteStringer.wrap(encryptionKey));
  }
  // We need this extra copy unfortunately to determine the final size of the
  // delimited output, see use of baos.size() below.
  builder.build().writeDelimitedTo(baos);
  baos.writeTo(output);
  // Pad to make up the difference between variable PB encoding length and the
  // length when encoded as writable under earlier V2 formats. Failure to pad
  // properly or if the PB encoding is too big would mean the trailer wont be read
  // in properly by HFile.
  int padding = getTrailerSize() - NOT_PB_SIZE - baos.size();
  if (padding < 0) {
    throw new IOException("Pbuf encoding size exceeded fixed trailer size limit");
  }
  for (int i = 0; i < padding; i++) {
    output.write(0);
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:42,代碼來源:FixedFileTrailer.java

示例11: realWrite

import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
public void realWrite(boolean printHeadBodyTags) throws IOException {
    flush();
    ByteArrayOutputStream stream = (ByteArrayOutputStream) this.out;
    this.out = outputStream;
    if (!printHeadBodyTags) {
        stream.writeTo(outputStream);
        return;
    }
    println("<html>");
    println("<head>");
    println("<style>");
    for (Style style : styles)
        println(style);
    println("</style>");
    println("</head>");

    String htmlText = new String(stream.toByteArray(), "UTF-8");
    Source source = new Source(htmlText);
    source.fullSequentialParse();

    List<StartTag> startTags = source.getAllStartTags("body");
    if (startTags.size() == 0) {
        println("<body>");
        println(htmlText);
        println("</body>");
    } else {
        println(new StringBuffer(startTags.get(0).getElement()));
    }

    println("</html>");
}
 
開發者ID:Vitaliy-Yakovchuk,項目名稱:ramus,代碼行數:32,代碼來源:Out.java

示例12: serialize

import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
/**
 * Write the trailer to a data stream. We support writing version 1 for
 * testing and for determining version 1 trailer size. It is also easy to see
 * what fields changed in version 2.
 *
 * @param outputStream
 * @throws IOException
 */
void serialize(DataOutputStream outputStream) throws IOException {
  HFile.checkFormatVersion(majorVersion);

  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  DataOutputStream baosDos = new DataOutputStream(baos);

  BlockType.TRAILER.write(baosDos);
  serializeAsPB(baosDos);

  // The last 4 bytes of the file encode the major and minor version universally
  baosDos.writeInt(materializeVersion(majorVersion, minorVersion));

  baos.writeTo(outputStream);
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:23,代碼來源:FixedFileTrailer.java

示例13: outputToJar

import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
/**
 * Generate output JAR-file and packages
 */
public void outputToJar() throws IOException {
    // create the manifest
    final Manifest manifest = new Manifest();
    final java.util.jar.Attributes atrs = manifest.getMainAttributes();
    atrs.put(java.util.jar.Attributes.Name.MANIFEST_VERSION, "1.2");

    final Map<String, Attributes> map = manifest.getEntries();
    // create manifest
    final String now = (new Date()).toString();
    final java.util.jar.Attributes.Name dateAttr =
        new java.util.jar.Attributes.Name("Date");

    final File jarFile = new File(_destDir, _jarFileName);
    final JarOutputStream jos =
        new JarOutputStream(new FileOutputStream(jarFile), manifest);

    for (JavaClass clazz : _bcelClasses) {
        final String className = clazz.getClassName().replace('.', '/');
        final java.util.jar.Attributes attr = new java.util.jar.Attributes();
        attr.put(dateAttr, now);
        map.put(className + ".class", attr);
        jos.putNextEntry(new JarEntry(className + ".class"));
        final ByteArrayOutputStream out = new ByteArrayOutputStream(2048);
        clazz.dump(out); // dump() closes it's output stream
        out.writeTo(jos);
    }
    jos.close();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:32,代碼來源:XSLTC.java

示例14: printNode

import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
public static void printNode(Node node) {
    DOMSource source = new DOMSource(node);
    String msgString = null;
    try {
        Transformer xFormer = TransformerFactory.newInstance().newTransformer();
        xFormer.setOutputProperty("omit-xml-declaration", "yes");
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        Result result = new StreamResult(outStream);
        xFormer.transform(source, result);
        outStream.writeTo(System.out);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:DomUtilTest.java

示例15: write

import java.io.ByteArrayOutputStream; //導入方法依賴的package包/類
@Override
public void write(Cell cell) throws IOException {
  if (encryptor == null) {
    super.write(cell);
    return;
  }

  byte[] iv = nextIv();
  encryptor.setIv(iv);
  encryptor.reset();

  // TODO: Check if this is a cell for an encrypted CF. If not, we can
  // write a 0 here to signal an unwrapped cell and just dump the KV bytes
  // afterward

  StreamUtils.writeRawVInt32(out, iv.length);
  out.write(iv);

  // TODO: Add support for WAL compression

  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  OutputStream cout = encryptor.createEncryptionStream(baos);

  int tlen = cell.getTagsLength();
  // Write the KeyValue infrastructure as VInts.
  StreamUtils.writeRawVInt32(cout, KeyValueUtil.keyLength(cell));
  StreamUtils.writeRawVInt32(cout, cell.getValueLength());
  // To support tags
  StreamUtils.writeRawVInt32(cout, tlen);

  // Write row, qualifier, and family
  StreamUtils.writeRawVInt32(cout, cell.getRowLength());
  cout.write(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength());
  StreamUtils.writeRawVInt32(cout, cell.getFamilyLength());
  cout.write(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength());
  StreamUtils.writeRawVInt32(cout, cell.getQualifierLength());
  cout.write(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength());
  // Write the rest ie. ts, type, value and tags parts
  StreamUtils.writeLong(cout, cell.getTimestamp());
  cout.write(cell.getTypeByte());
  cout.write(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength());
  if (tlen > 0) {
    cout.write(cell.getTagsArray(), cell.getTagsOffset(), tlen);
  }
  cout.close();

  StreamUtils.writeRawVInt32(out, baos.size());
  baos.writeTo(out);

  // Increment IV given the final payload length
  incrementIv(baos.size());
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:53,代碼來源:SecureWALCellCodec.java


注:本文中的java.io.ByteArrayOutputStream.writeTo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。