本文整理了Java中org.apache.commons.io.output.ByteArrayOutputStream.close()
方法的一些代码示例,展示了ByteArrayOutputStream.close()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteArrayOutputStream.close()
方法的具体详情如下:
包路径:org.apache.commons.io.output.ByteArrayOutputStream
类名称:ByteArrayOutputStream
方法名:close
[英]Closing a ByteArrayOutputStream has no effect. The methods in this class can be called after the stream has been closed without generating an IOException.
[中]关闭ByteArrayOutputStream无效。此类中的方法可以在流关闭后调用,而不会生成IOException。
代码示例来源:origin: apache/hive
public static byte[] serializeJobConf(JobConf jobConf) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
jobConf.write(new DataOutputStream(out));
} catch (IOException e) {
LOG.error("Error serializing job configuration: " + e, e);
return null;
} finally {
try {
out.close();
} catch (IOException e) {
LOG.error("Error closing output stream: " + e, e);
}
}
return out.toByteArray();
}
代码示例来源:origin: apache/drill
public static byte[] serializeJobConf(JobConf jobConf) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
jobConf.write(new DataOutputStream(out));
} catch (IOException e) {
LOG.error("Error serializing job configuration: " + e, e);
return null;
} finally {
try {
out.close();
} catch (IOException e) {
LOG.error("Error closing output stream: " + e, e);
}
}
return out.toByteArray();
}
代码示例来源:origin: apache/flume
return eventList;
} finally {
outputStream.close();
inputStream.close();
代码示例来源:origin: apache/incubator-gobblin
/**
* Encrypt a test string with a symmetric key and check that it can be decrypted
* @throws IOException
* @throws PGPException
*/
@Test
public void encryptSym() throws IOException, PGPException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStream os = GPGFileEncryptor.encryptFile(baos, PASSWORD, "DES");
os.write(EXPECTED_FILE_CONTENT_BYTES);
os.close();
baos.close();
byte[] encryptedBytes = baos.toByteArray();
try (InputStream is = GPGFileDecryptor.decryptFile(new ByteArrayInputStream(encryptedBytes), "test")) {
byte[] decryptedBytes = IOUtils.toByteArray(is);
Assert.assertNotEquals(EXPECTED_FILE_CONTENT_BYTES, encryptedBytes);
Assert.assertEquals(EXPECTED_FILE_CONTENT_BYTES, decryptedBytes);
}
}
代码示例来源:origin: apache/incubator-gobblin
/**
* Encrypt a test string with an asymmetric key and check that it can be decrypted
* @throws IOException
* @throws PGPException
*/
@Test
public void encryptAsym() throws IOException, PGPException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStream os = GPGFileEncryptor.encryptFile(baos, getClass().getResourceAsStream(PUBLIC_KEY),
Long.parseUnsignedLong(KEY_ID, 16), "CAST5");
os.write(EXPECTED_FILE_CONTENT_BYTES);
os.close();
baos.close();
byte[] encryptedBytes = baos.toByteArray();
try (InputStream is = GPGFileDecryptor.decryptFile(new ByteArrayInputStream(encryptedBytes),
getClass().getResourceAsStream(PRIVATE_KEY), PASSPHRASE)) {
byte[] decryptedBytes = IOUtils.toByteArray(is);
Assert.assertNotEquals(EXPECTED_FILE_CONTENT_BYTES, encryptedBytes);
Assert.assertEquals(EXPECTED_FILE_CONTENT_BYTES, decryptedBytes);
}
}
代码示例来源:origin: voldemort/voldemort
} catch(MessagingException me) {
logger.error("Exception while constructing key body headers", me);
keysOutputStream.close();
throw me;
} catch(MessagingException me) {
logger.error("Exception while constructing value body part", me);
keysOutputStream.close();
throw me;
} catch(MessagingException me) {
logger.error("Exception while constructing key body part", me);
keysOutputStream.close();
throw me;
keysOutputStream.close();
代码示例来源:origin: AsyncHttpClient/async-http-client
@Test(expectedExceptions = NtlmEngineException.class)
public void testGenerateType3MsgThworsExceptionWhenType2IndicatorNotPresent() throws IOException {
ByteArrayOutputStream buf = new ByteArrayOutputStream();
buf.write("NTLMSSP".getBytes(StandardCharsets.US_ASCII));
buf.write(0);
// type 2 indicator
buf.write(3);
buf.write(0);
buf.write(0);
buf.write(0);
buf.write("challenge".getBytes());
NtlmEngine engine = new NtlmEngine();
engine.generateType3Msg("username", "password", "localhost", "workstation", Base64.getEncoder().encodeToString(buf.toByteArray()));
buf.close();
fail("An NtlmEngineException must have occurred as type 2 indicator is incorrect");
}
代码示例来源:origin: commons-io/commons-io
@Test
public void testToInputStream() throws IOException {
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 more writes
final InputStream in = baout.toInputStream();
byte refData[] = ref.toByteArray();
//Write some more data
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 all data written
baoutData = IOUtils.toByteArray(baout.toInputStream());
refData = ref.toByteArray();
assertEquals(8254, baoutData.length);
checkByteArrays(refData, baoutData);
baout.close();
in.close();
}
代码示例来源:origin: voldemort/voldemort
} catch(MessagingException me) {
logger.error("Exception while constructing body part", me);
outputStream.close();
throw me;
} catch(Exception e) {
logger.error("Exception while writing multipart to output stream", e);
outputStream.close();
throw e;
outputStream.close();
代码示例来源: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
final ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
assertSame(baos1.toByteArray(), baos2.toByteArray());
baos1.close();
baos2.close();
baout.close();
baout1.close();
代码示例来源:origin: AsyncHttpClient/async-http-client
@Test(expectedExceptions = NtlmEngineException.class)
public void testGenerateType3MsgThrowsExceptionWhenUnicodeSupportNotIndicated() throws IOException {
ByteArrayOutputStream buf = new ByteArrayOutputStream();
buf.write("NTLMSSP".getBytes(StandardCharsets.US_ASCII));
buf.write(0);
// type 2 indicator
buf.write(2);
buf.write(0);
buf.write(0);
buf.write(0);
buf.write(longToBytes(1L)); // we want to write a Long
// flags
buf.write(0);// unicode support indicator
buf.write(0);
buf.write(0);
buf.write(0);
buf.write(longToBytes(1L));// challenge
NtlmEngine engine = new NtlmEngine();
engine.generateType3Msg("username", "password", "localhost", "workstation", Base64.getEncoder().encodeToString(buf.toByteArray()));
buf.close();
fail("An NtlmEngineException must have occurred as unicode support is not indicated");
}
代码示例来源:origin: apache/hive
private <K, V> String explainToString(Map<K, V> explainMap) throws Exception {
ExplainWork work = new ExplainWork();
ParseContext pCtx = new ParseContext();
HashMap<String, TableScanOperator> topOps = new HashMap<>();
TableScanOperator scanOp = new DummyOperator(new DummyExplainDesc<K, V>(explainMap));
topOps.put("sample", scanOp);
pCtx.setTopOps(topOps);
work.setParseContext(pCtx);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
work.setConfig(new ExplainConfiguration());
ExplainTask newExplainTask = new ExplainTask();
newExplainTask.queryState = uut.queryState;
newExplainTask.getJSONLogicalPlan(new PrintStream(baos), work);
baos.close();
return baos.toString();
}
代码示例来源:origin: AsyncHttpClient/async-http-client
@Test
public void testGenerateType3Msg() throws IOException {
ByteArrayOutputStream buf = new ByteArrayOutputStream();
buf.write("NTLMSSP".getBytes(StandardCharsets.US_ASCII));
buf.write(0);
// type 2 indicator
buf.write(2);
buf.write(0);
buf.write(0);
buf.write(0);
buf.write(longToBytes(0L)); // we want to write a Long
// flags
buf.write(1);// unicode support indicator
buf.write(0);
buf.write(0);
buf.write(0);
buf.write(longToBytes(1L));// challenge
NtlmEngine engine = new NtlmEngine();
String type3Msg = engine.generateType3Msg("username", "password", "localhost", "workstation",
Base64.getEncoder().encodeToString(buf.toByteArray()));
buf.close();
assertEquals(
type3Msg,
"TlRMTVNTUAADAAAAGAAYAEgAAAAYABgAYAAAABIAEgB4AAAAEAAQAIoAAAAWABYAmgAAAAAAAACwAAAAAQAAAgUBKAoAAAAP1g6lqqN1HZ0wSSxeQ5riQkyh7/UexwVlCPQm0SHU2vsDQm2wM6NbT2zPonPzLJL0TABPAEMAQQBMAEgATwBTAFQAdQBzAGUAcgBuAGEAbQBlAFcATwBSAEsAUwBUAEEAVABJAE8ATgA=",
"Incorrect type3 message generated");
}
代码示例来源:origin: opensourceBIM/BIMserver
@Override
public void close() throws IOException {
super.close();
data = this.toByteArray();
}
};
代码示例来源:origin: opensourceBIM/BIMserver
@Override
public void close() throws IOException {
super.close();
data = this.toByteArray();
}
};
代码示例来源:origin: Lihuanghe/SMSGate
public static byte[] write(Serializable obj) throws Exception{
ByteArrayOutputStream arroutput = new ByteArrayOutputStream();
FSTObjectOutput objoutput = conf.get().getObjectOutput(arroutput);
try{
objoutput.writeObject(obj);
objoutput.flush();
return arroutput.toByteArray();
}finally{
arroutput.close();
}
}
代码示例来源:origin: io.github.jiri-meluzin/io.github.jiri-meluzin.tibcobwutils.deploymentrepository
@Override
public void close() throws IOException {
super.close();
modify();
content = toByteArray();
}
};
代码示例来源:origin: info.magnolia/magnolia-core
@Override
public void tearDown() throws Exception {
super.tearDown();
outputStream.close();
}
代码示例来源:origin: info.magnolia.core/magnolia-configuration
@After
public void tearDown() throws Exception {
MgnlContext.setInstance(null);
outputStream.close();
}
内容来源于网络,如有侵权,请联系作者删除!