本文整理了Java中java.io.ByteArrayOutputStream.writeTo()
方法的一些代码示例,展示了ByteArrayOutputStream.writeTo()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteArrayOutputStream.writeTo()
方法的具体详情如下:
包路径:java.io.ByteArrayOutputStream
类名称:ByteArrayOutputStream
方法名:writeTo
[英]Takes the contents of this stream and writes it to the output stream out.
[中]获取此流的内容并将其写入输出流。
代码示例来源:origin: spring-projects/spring-framework
/**
* 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();
}
代码示例来源:origin: spring-projects/spring-framework
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
HttpServletResponse response) throws Exception {
Object toBeMarshalled = locateToBeMarshalled(model);
if (toBeMarshalled == null) {
throw new IllegalStateException("Unable to locate object to be marshalled in model: " + model);
}
Assert.state(this.marshaller != null, "No Marshaller set");
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
this.marshaller.marshal(toBeMarshalled, new StreamResult(baos));
setResponseContentType(request, response);
response.setContentLength(baos.size());
baos.writeTo(response.getOutputStream());
}
代码示例来源:origin: stackoverflow.com
try {
FileOutputStream fos = new FileOutputStream (new File("myFile"));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// Put data in your baos
baos.writeTo(fos);
} catch(IOException ioe) {
// Handle exception here
ioe.printStackTrace();
} finally {
fos.close();
}
代码示例来源:origin: apache/nifi
private <T> void serialize(final T value, final Serializer<T> serializer, final DataOutputStream dos) throws IOException {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
serializer.serialize(value, baos);
dos.writeInt(baos.size());
baos.writeTo(dos);
}
代码示例来源:origin: real-logic/aeron
public static void saveExistingErrors(final File markFile, final AtomicBuffer errorBuffer, final PrintStream logger)
{
try
{
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final int observations = saveErrorLog(new PrintStream(baos, false, "UTF-8"), errorBuffer);
if (observations > 0)
{
final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss-SSSZ");
final String errorLogFilename =
markFile.getParent() + '-' + dateFormat.format(new Date()) + "-error.log";
if (null != logger)
{
logger.println("WARNING: Existing errors saved to: " + errorLogFilename);
}
try (FileOutputStream out = new FileOutputStream(errorLogFilename))
{
baos.writeTo(out);
}
}
}
catch (final Exception ex)
{
LangUtil.rethrowUnchecked(ex);
}
}
代码示例来源:origin: libgdx/libgdx
public void endChunk (DataOutputStream target) throws IOException {
flush();
target.writeInt(buffer.size() - 4);
buffer.writeTo(target);
target.writeInt((int)crc.getValue());
buffer.reset();
crc.reset();
}
}
代码示例来源:origin: apache/nifi
private <T> void serialize(final Set<T> values, final Serializer<T> serializer, final DataOutputStream dos) throws IOException {
// Write the number of elements to follow, then each element and its size
dos.writeInt(values.size());
for(T value : values) {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
serializer.serialize(value, baos);
dos.writeInt(baos.size());
baos.writeTo(dos);
}
}
代码示例来源:origin: real-logic/aeron
private static void reportExistingErrors(final Context ctx, final MappedByteBuffer cncByteBuffer)
{
try
{
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final int observations = ctx.saveErrorLog(new PrintStream(baos, false, "UTF-8"), cncByteBuffer);
if (observations > 0)
{
final StringBuilder builder = new StringBuilder(ctx.aeronDirectoryName());
removeTrailingSlashes(builder);
final SimpleDateFormat dateFormat = new SimpleDateFormat("-yyyy-MM-dd-HH-mm-ss-SSSZ");
builder.append(dateFormat.format(new Date())).append("-error.log");
final String errorLogFilename = builder.toString();
System.err.println("WARNING: Existing errors saved to: " + errorLogFilename);
try (FileOutputStream out = new FileOutputStream(errorLogFilename))
{
baos.writeTo(out);
}
}
}
catch (final Exception ex)
{
LangUtil.rethrowUnchecked(ex);
}
}
代码示例来源:origin: libgdx/libgdx
public void endChunk (DataOutputStream target) throws IOException {
flush();
target.writeInt(buffer.size() - 4);
buffer.writeTo(target);
target.writeInt((int)crc.getValue());
buffer.reset();
crc.reset();
}
}
代码示例来源:origin: apache/nifi
@Override
public void writeHeader(final long firstEventId, final DataOutputStream out) throws IOException {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
eventSchema.writeTo(baos);
out.writeInt(baos.size());
baos.writeTo(out);
}
代码示例来源:origin: apache/nifi
public void update(final Collection<S> records, final long transactionId, final Map<Object, S> recordMap, final boolean forceSync) throws IOException {
try (final ByteArrayOutputStream baos = new ByteArrayOutputStream(256);
final DataOutputStream out = new DataOutputStream(baos)) {
out.writeLong(transactionId);
final int numEditsToSerialize = records.size();
int editsSerialized = 0;
for (final S record : records) {
final Object recordId = serde.getRecordIdentifier(record);
final S previousVersion = recordMap.get(recordId);
serde.serializeEdit(previousVersion, record, out);
if (++editsSerialized < numEditsToSerialize) {
out.write(TRANSACTION_CONTINUE);
} else {
out.write(TRANSACTION_COMMIT);
}
}
out.flush();
if (this.closed) {
throw new IllegalStateException("Partition is closed");
}
baos.writeTo(dataOut);
dataOut.flush();
if (forceSync) {
synchronized (fileOut) {
fileOut.getFD().sync();
}
}
}
}
代码示例来源:origin: jersey/jersey
private void flushBuffer(boolean endOfStream) throws IOException {
if (!directWrite) {
int currentSize;
if (endOfStream) {
currentSize = buffer == null ? 0 : buffer.size();
} else {
currentSize = -1;
}
commitStream(currentSize);
if (buffer != null) {
buffer.writeTo(adaptedOutput);
}
}
}
代码示例来源:origin: apache/nifi
@Override
protected void writeRecord(final ProvenanceEventRecord event, final long eventId, final DataOutputStream out) throws IOException {
try (final ByteArrayOutputStream baos = new ByteArrayOutputStream(256)) {
final Record eventRecord = createRecord(event, eventId);
recordWriter.writeRecord(eventRecord, baos);
out.writeInt(baos.size());
baos.writeTo(out);
}
}
}
代码示例来源:origin: apache/hbase
/**
* 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);
}
代码示例来源:origin: jersey/jersey
private void flushBuffer(boolean endOfStream) throws IOException {
if (!directWrite) {
int currentSize;
if (endOfStream) {
currentSize = buffer == null ? 0 : buffer.size();
} else {
currentSize = -1;
}
commitStream(currentSize);
if (buffer != null) {
buffer.writeTo(adaptedOutput);
}
}
}
代码示例来源:origin: org.springframework/spring-webmvc
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
HttpServletResponse response) throws Exception {
Object toBeMarshalled = locateToBeMarshalled(model);
if (toBeMarshalled == null) {
throw new IllegalStateException("Unable to locate object to be marshalled in model: " + model);
}
Assert.state(this.marshaller != null, "No Marshaller set");
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
this.marshaller.marshal(toBeMarshalled, new StreamResult(baos));
setResponseContentType(request, response);
response.setContentLength(baos.size());
baos.writeTo(response.getOutputStream());
}
代码示例来源:origin: xalan/xalan
final String className = clazz.getClassName().replace('.','/');
jos.putNextEntry(new JarEntry(className+".class"));
final ByteArrayOutputStream out = new ByteArrayOutputStream(2048);
out.writeTo(jos);
代码示例来源:origin: org.springframework/spring-webmvc
/**
* 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();
}
代码示例来源:origin: prestodb/presto
public static byte[] encodeOid(String oid)
{
requireNonNull(oid, "oid is null");
List<Integer> parts = Splitter.on('.').splitToList(oid).stream()
.map(Integer::parseInt)
.collect(toImmutableList());
checkArgument(parts.size() >= 2, "at least 2 parts are required");
try {
ByteArrayOutputStream body = new ByteArrayOutputStream();
body.write(parts.get(0) * 40 + parts.get(1));
for (Integer part : parts.subList(2, parts.size())) {
writeOidPart(body, part);
}
byte[] length = encodeLength(body.size());
ByteArrayOutputStream out = new ByteArrayOutputStream();
out.write(OBJECT_IDENTIFIER_TAG);
out.write(length);
body.writeTo(out);
return out.toByteArray();
}
catch (IOException e) {
// this won't happen with byte array output streams
throw new UncheckedIOException(e);
}
}
代码示例来源:origin: CarGuo/GSYVideoPlayer
ByteArrayOutputStream baos = new ByteArrayOutputStream();
AnimatedGifEncoder localAnimatedGifEncoder = new AnimatedGifEncoder();
baos.writeTo(fos);
baos.flush();
fos.flush();
内容来源于网络,如有侵权,请联系作者删除!