Improve usage of ByteArrayOutputStream/ByteArrayInputStream
Closes gh-24805
This commit is contained in:
committed by
Sam Brannen
parent
821984a5cf
commit
e63d1cf12d
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -202,15 +202,10 @@ public class ConcurrentMapCache extends AbstractValueAdaptingCache {
|
||||
}
|
||||
}
|
||||
|
||||
private Object serializeValue(SerializationDelegate serialization, Object storeValue) throws IOException {
|
||||
private static Object serializeValue(SerializationDelegate serialization, Object storeValue) throws IOException {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
try {
|
||||
serialization.serialize(storeValue, out);
|
||||
return out.toByteArray();
|
||||
}
|
||||
finally {
|
||||
out.close();
|
||||
}
|
||||
serialization.serialize(storeValue, out);
|
||||
return out.toByteArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -229,14 +224,9 @@ public class ConcurrentMapCache extends AbstractValueAdaptingCache {
|
||||
|
||||
}
|
||||
|
||||
private Object deserializeValue(SerializationDelegate serialization, Object storeValue) throws IOException {
|
||||
private static Object deserializeValue(SerializationDelegate serialization, Object storeValue) throws IOException {
|
||||
ByteArrayInputStream in = new ByteArrayInputStream((byte[]) storeValue);
|
||||
try {
|
||||
return serialization.deserialize(in);
|
||||
}
|
||||
finally {
|
||||
in.close();
|
||||
}
|
||||
return serialization.deserialize(in);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user