本文整理了Java中java.io.ByteArrayInputStream.close()
方法的一些代码示例,展示了ByteArrayInputStream.close()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteArrayInputStream.close()
方法的具体详情如下:
包路径:java.io.ByteArrayInputStream
类名称:ByteArrayInputStream
方法名:close
[英]Closes this stream and frees resources associated with this stream.
[中]关闭此流并释放与此流关联的资源。
代码示例来源:origin: spring-projects/spring-framework
private Object deserializeValue(SerializationDelegate serialization, Object storeValue) throws IOException {
ByteArrayInputStream in = new ByteArrayInputStream((byte[]) storeValue);
try {
return serialization.deserialize(in);
}
finally {
in.close();
}
}
代码示例来源:origin: apache/rocketmq-externals
public static Serializable objectDeserialize(byte[] bytes) throws IOException, ClassNotFoundException {
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bais);
ois.close();
bais.close();
return (Serializable) ois.readObject();
}
代码示例来源:origin: plantuml/plantuml
public byte[] decompress(byte[] in) throws IOException {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final ByteArrayInputStream bais = new ByteArrayInputStream(in);
final InflaterInputStream gz = new InflaterInputStream(bais);
int read;
while ((read = gz.read()) != -1) {
baos.write(read);
}
gz.close();
bais.close();
baos.close();
return baos.toByteArray();
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testChannelWritelong() throws IOException
{
final int index = 0;
WritableByteChannel channelOutput = Channels.newChannel(outStream);
serializerUtils.writeLong(channelOutput, longs[index]);
ByteArrayInputStream inputstream = new ByteArrayInputStream(outStream.toByteArray());
channelOutput.close();
inputstream.close();
long expected = serializerUtils.readLong(inputstream);
long actuals = longs[index];
Assert.assertEquals(expected, actuals);
}
代码示例来源:origin: org.mockito/mockito-core
ByteArrayInputStream bis = new ByteArrayInputStream(serializedMock);
ObjectInputStream objectInputStream = new MockitoMockObjectInputStream(bis, typeToMock, extraInterfaces);
Object deserializedMock = objectInputStream.readObject();
bis.close();
objectInputStream.close();
代码示例来源:origin: kiegroup/jbpm
public static Serializable deserialize( byte[] byteArray, ClassLoader classLoader ) throws IOException, ClassNotFoundException {
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(classLoader);
ByteArrayInputStream byteArrayIn = new ByteArrayInputStream(byteArray);
ObjectInput objectIn = null;
Serializable result;
try {
objectIn = new ObjectInputStream(byteArrayIn);
result = (Serializable) objectIn.readObject();
} finally {
try {
byteArrayIn.close();
} catch( IOException ex ) {
// ignore close exception
}
try {
if( objectIn != null ) {
objectIn.close();
}
} catch( IOException ex ) {
// ignore close exception
}
Thread.currentThread().setContextClassLoader(originalClassLoader);
}
return result;
}
代码示例来源:origin: apache/geode
public static Object unzip(byte[] blob) throws IOException, ClassNotFoundException {
// logger.info("CacheServerHelper: Unzipping blob to object: " + blob);
ByteArrayInputStream bais = new ByteArrayInputStream(blob);
GZIPInputStream gs = new GZIPInputStream(bais);
ObjectInputStream ois = new ObjectInputStream(gs);
Object obj = ois.readObject();
// logger.info("CacheServerHelper: Unzipped blob to object: " + obj);
ois.close();
bais.close();
return obj;
}
代码示例来源:origin: apache/flink
@Override
public NFAState copy(NFAState from) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
serialize(from, new DataOutputViewStreamWrapper(baos));
baos.close();
byte[] data = baos.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(data);
NFAState copy = deserialize(new DataInputViewStreamWrapper(bais));
bais.close();
return copy;
} catch (IOException e) {
throw new RuntimeException("Could not copy NFA.", e);
}
}
代码示例来源:origin: redisson/redisson
/**
* Loads properties from string.
*/
public static void loadFromString(Properties p, String data) throws IOException {
ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes(StringPool.ISO_8859_1));
try {
p.load(is);
} finally {
is.close();
}
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testChannelWriteString() throws IOException
{
final int index = 0;
WritableByteChannel channelOutput = Channels.newChannel(outStream);
serializerUtils.writeString(channelOutput, strings[index]);
ByteArrayInputStream inputstream = new ByteArrayInputStream(outStream.toByteArray());
channelOutput.close();
inputstream.close();
String expected = serializerUtils.readString(inputstream);
String actuals = strings[index];
Assert.assertEquals(expected, actuals);
}
代码示例来源:origin: org.powermock/powermock-api-mockito
ByteArrayInputStream bis = new ByteArrayInputStream(serializedMock);
ObjectInputStream objectInputStream = new MockitoMockObjectInputStream(bis, typeToMock, extraInterfaces);
Object deserializedMock = objectInputStream.readObject();
bis.close();
objectInputStream.close();
代码示例来源:origin: apache/flink
private static void skipCondition(DataInputView in) throws IOException, ClassNotFoundException {
boolean hasCondition = in.readBoolean();
if (hasCondition) {
int length = in.readInt();
byte[] serCondition = new byte[length];
in.read(serCondition);
ByteArrayInputStream bais = new ByteArrayInputStream(serCondition);
ObjectInputStream ois = new ObjectInputStream(bais);
ois.readObject();
ois.close();
bais.close();
}
}
代码示例来源:origin: stackoverflow.com
public static byte[] compress(String string) throws IOException {
ByteArrayOutputStream os = new ByteArrayOutputStream(string.length());
GZIPOutputStream gos = new GZIPOutputStream(os);
gos.write(string.getBytes());
gos.close();
byte[] compressed = os.toByteArray();
os.close();
return compressed;
}
public static String decompress(byte[] compressed) throws IOException {
final int BUFFER_SIZE = 32;
ByteArrayInputStream is = new ByteArrayInputStream(compressed);
GZIPInputStream gis = new GZIPInputStream(is, BUFFER_SIZE);
StringBuilder string = new StringBuilder();
byte[] data = new byte[BUFFER_SIZE];
int bytesRead;
while ((bytesRead = gis.read(data)) != -1) {
string.append(new String(data, 0, bytesRead));
}
gis.close();
is.close();
return string.toString();
}
代码示例来源:origin: org.springframework/spring-context
private Object deserializeValue(SerializationDelegate serialization, Object storeValue) throws IOException {
ByteArrayInputStream in = new ByteArrayInputStream((byte[]) storeValue);
try {
return serialization.deserialize(in);
}
finally {
in.close();
}
}
代码示例来源:origin: commons-collections/commons-collections
ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
ByteArrayInputStream bais = null;
try {
out.writeObject(iPrototype);
bais = new ByteArrayInputStream(baos.toByteArray());
ObjectInputStream in = new ObjectInputStream(bais);
return in.readObject();
try {
if (bais != null) {
bais.close();
baos.close();
代码示例来源:origin: plantuml/plantuml
private Image getAviImage(AffineTransformation affineTransform) throws IOException {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
writeImageInternal(new FileFormatOption(FileFormat.PNG), 42, baos, Animation.singleton(affineTransform));
baos.close();
final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
final Image im = ImageIO.read(bais);
bais.close();
return im;
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
public Savable load(byte[] data) throws IOException {
ByteArrayInputStream bais = new ByteArrayInputStream(data);
Savable rVal = load(bais);
bais.close();
return rVal;
}
代码示例来源:origin: killme2008/Metamorphosis
ObjectInputStream ois = null;
try {
bais = new ByteArrayInputStream(objContent);
ois = new ObjectInputStream(bais);
obj = ois.readObject();
try {
ois.close();
bais.close();
代码示例来源:origin: plantuml/plantuml
private BufferedImage getImage() throws IOException, InterruptedException {
final Diagram system = getSystem();
final ByteArrayOutputStream os = new ByteArrayOutputStream();
system.exportDiagram(os, 0, new FileFormatOption(FileFormat.PNG));
os.close();
final ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
final BufferedImage im = ImageIO.read(is);
is.close();
return im;
}
代码示例来源:origin: aws/aws-sdk-java
/**
* Returns the deserialized transfer state of the given serialized
* representation.
*
* @throws UnsupportedOperationException
* if the paused transfer type extracted from the serialized
* representation is not supported.
*/
public static <T extends PersistableTransfer> T deserializeFrom(
String serialized) {
if (serialized == null)
return null;
ByteArrayInputStream byteStream = new ByteArrayInputStream(
serialized.getBytes(UTF8));
try{
return deserializeFrom(byteStream);
}finally{
try { byteStream.close(); } catch(IOException ioe) { } ;
}
}
}
内容来源于网络,如有侵权,请联系作者删除!