本文整理了Java中org.apache.commons.io.output.ByteArrayOutputStream.flush()
方法的一些代码示例,展示了ByteArrayOutputStream.flush()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteArrayOutputStream.flush()
方法的具体详情如下:
包路径:org.apache.commons.io.output.ByteArrayOutputStream
类名称:ByteArrayOutputStream
方法名:flush
暂无
代码示例来源:origin: apache/metron
/**
* Serialize a profile measurement's value.
*
* The value produced by a Profile definition can be any numeric data type. The data
* type depends on how the profile is defined by the user. The user should be able to
* choose the data type that is most suitable for their use case.
*
* @param value The value to serialize.
*/
public static byte[] toBytes(Object value) {
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Output output = new Output(bos);
kryo.get().writeClassAndObject(output, value);
output.flush();
bos.flush();
return bos.toByteArray();
}
catch(Throwable t) {
LOG.error("Unable to serialize: " + value + " because " + t.getMessage(), t);
throw new IllegalStateException("Unable to serialize " + value + " because " + t.getMessage(), t);
}
}
代码示例来源:origin: apache/metron
/**
* Serialize a profile measurement's value.
*
* The value produced by a Profile definition can be any numeric data type. The data
* type depends on how the profile is defined by the user. The user should be able to
* choose the data type that is most suitable for their use case.
*
* @param value The value to serialize.
*/
public static byte[] toBytes(Object value) {
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Output output = new Output(bos);
kryo.get().writeClassAndObject(output, value);
output.flush();
bos.flush();
return bos.toByteArray();
}
catch(Throwable t) {
LOG.error("Unable to serialize: {} because {}", value, t.getMessage(), t);
throw new IllegalStateException("Unable to serialize " + value + " because " + t.getMessage(), t);
}
}
代码示例来源:origin: com.sangupta/jerry-web
/**
* @see java.io.OutputStream#flush()
*/
@Override
public void flush() throws IOException {
this.writer.flush();
this.outputStream.flush();
}
代码示例来源:origin: com.sangupta/am
/**
* @see java.io.OutputStream#flush()
*/
@Override
public void flush() throws IOException {
this.writer.flush();
this.outputStream.flush();
}
代码示例来源:origin: miltonio/milton2
@Override
public void flush() throws IOException {
if (tempMemoryBuffer != null) {
tempMemoryBuffer.flush();
} else {
bufOut.flush();
fout.flush();
}
}
代码示例来源:origin: apache/nifi-minifi
protected static void writeNiFiPropertiesFile(ByteArrayOutputStream nifiPropertiesOutputStream, String destPath) throws IOException {
final Path nifiPropertiesPath = Paths.get(destPath, "nifi.properties");
try (FileOutputStream nifiProperties = new FileOutputStream(nifiPropertiesPath.toString())) {
nifiPropertiesOutputStream.writeTo(nifiProperties);
} finally {
if (nifiPropertiesOutputStream != null) {
nifiPropertiesOutputStream.flush();
nifiPropertiesOutputStream.close();
}
}
}
代码示例来源:origin: wso2/wso2-synapse
/**
* Returns a copy of the JSON stream contained in the provided Message Context.
*
* @param messageContext Axis2 Message context that contains a JSON payload.
* @return {@link java.io.InputStream}
*/
private static InputStream copyOfJsonPayload(MessageContext messageContext, boolean closable) {
if (messageContext == null) {
logger.error("#copyOfJsonPayload. Cannot copy JSON stream from message context. [null].");
return null;
}
InputStream jsonStream = jsonStream(messageContext, true);
if (jsonStream == null) {
logger.error("#copyOfJsonPayload. Cannot copy JSON stream from message context. [null] stream.");
return null;
}
org.apache.commons.io.output.ByteArrayOutputStream out = new org.apache.commons.io.output.ByteArrayOutputStream();
try {
IOUtils.copy(jsonStream, out);
out.flush();
return closable ? new ByteArrayInputStream(out.toByteArray())
: toReadOnlyStream(new ByteArrayInputStream(out.toByteArray()));
} catch (IOException e) {
logger.error("#copyOfJsonPayload. Could not copy the JSON stream from message context. Error>>> " + e.getLocalizedMessage());
}
return null;
}
代码示例来源:origin: wso2/wso2-synapse
/**
* Returns a reader that can read from the JSON payload contained in the provided message context as a JavaScript source.<br/>
* The reader returns the '(' character at the beginning of the stream and marks the end with the ')' character.<br/>
* The reader returned by this method can be directly used with the JavaScript {@link javax.script.ScriptEngine#eval(java.io.Reader)} method.
*
* @param messageContext Axis2 Message context
* @return {@link java.io.InputStreamReader}
*/
public static Reader newJavaScriptSourceReader(MessageContext messageContext) {
InputStream jsonStream = jsonStream(messageContext, true);
if (jsonStream == null) {
logger.error("#newJavaScriptSourceReader. Could not create a JavaScript source. Error>>> No JSON stream found.");
return null;
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
out.write('(');
IOUtils.copy(jsonStream, out);
out.write(')');
out.flush();
} catch (IOException e) {
logger.error("#newJavaScriptSourceReader. Could not create a JavaScript source. Error>>> " + e.getLocalizedMessage());
return null;
}
return new InputStreamReader(new ByteArrayInputStream(out.toByteArray()));
}
代码示例来源:origin: wso2/wso2-synapse
try {
IOUtils.copy(jsonStream, out);
out.flush();
InputStream inputStream = toReadOnlyStream(new ByteArrayInputStream(out.toByteArray()));
messageContext.setProperty(inputStreamCache, inputStream);
代码示例来源:origin: wso2/wso2-synapse
stream.write(END_ARRAY.getBytes());
stream.flush();
this.stream = stream.toByteArray();
if (logger.isDebugEnabled()) {
代码示例来源:origin: org.mule.transports/mule-transport-tcp
baos.flush();
baos.close();
代码示例来源:origin: wso2/wso2-synapse
new org.apache.commons.io.output.ByteArrayOutputStream();
element.serialize(xmlStream);
xmlStream.flush();
xmlEventReader = xmlInputFactory.createXMLEventReader(
new XmlReaderDelegate(xmlInputFactory.createXMLStreamReader(
代码示例来源:origin: dbs-leipzig/gradoop
public static <T extends Value> T writeAndReadFields(Class<T> clazz, T in) throws IOException {
// write to byte[]
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
DataOutputView outputView = new DataOutputViewStreamWrapper(outputStream);
in.write(outputView);
outputStream.flush();
T out;
try {
out = clazz.newInstance();
} catch (Exception e) {
e.printStackTrace();
throw new IOException("Cannot initialize the class: " + clazz);
}
// read from byte[]
ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
DataInputView inputView = new DataInputViewStreamWrapper(inputStream);
out.read(inputView);
return out;
}
代码示例来源:origin: org.mule.transports/mule-transport-http
bos.flush();
byte[] result = bos.toByteArray();
outstream.close();
内容来源于网络,如有侵权,请联系作者删除!