Improve usage of ByteArrayOutputStream/ByteArrayInputStream

Closes gh-24805
This commit is contained in:
Сергей Цыпанов
2020-03-28 19:24:09 +02:00
committed by Sam Brannen
parent 821984a5cf
commit e63d1cf12d
10 changed files with 47 additions and 40 deletions

View File

@@ -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);
}
}