simplification: use try-with-resources in classes from intellij.platform.util module

This commit is contained in:
nik
2019-02-11 18:48:18 +03:00
parent 6ea6b10a3c
commit 0845c6afc1
23 changed files with 64 additions and 270 deletions
@@ -224,10 +224,8 @@ public class UnixProcessManager {
}
private static void processCommandOutput(Process process, Processor<? super String> processor, boolean skipFirstLine, boolean throwOnError) throws IOException {
BufferedReader stdOutput = new BufferedReader(new InputStreamReader(process.getInputStream()));
try {
BufferedReader stdError = new BufferedReader(new InputStreamReader(process.getErrorStream()));
try {
try (BufferedReader stdOutput = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
try (BufferedReader stdError = new BufferedReader(new InputStreamReader(process.getErrorStream()))) {
if (skipFirstLine) {
stdOutput.readLine(); //ps output header
}
@@ -247,12 +245,6 @@ public class UnixProcessManager {
throw new IOException("Error reading ps output:" + errorStr.toString());
}
}
finally {
stdError.close();
}
}
finally {
stdOutput.close();
}
}
@@ -420,8 +420,7 @@ public class PathManager {
for (String path : paths) {
if (path != null && new File(path).exists()) {
try {
Reader fis = new BufferedReader(new FileReader(path));
try {
try (Reader fis = new BufferedReader(new FileReader(path))) {
Map<String, String> properties = FileUtil.loadProperties(fis);
for (Map.Entry<String, String> entry : properties.entrySet()) {
String key = entry.getKey();
@@ -433,9 +432,6 @@ public class PathManager {
}
}
}
finally {
fis.close();
}
}
catch (IOException e) {
log("Can't read property file '" + path + "': " + e.getMessage());
@@ -355,13 +355,9 @@ public class JDOMUtil {
}
public static void writeDocument(@NotNull Document document, @NotNull String filePath, String lineSeparator) throws IOException {
OutputStream stream = new BufferedOutputStream(new FileOutputStream(filePath));
try {
try (OutputStream stream = new BufferedOutputStream(new FileOutputStream(filePath))) {
writeDocument(document, stream, lineSeparator);
}
finally {
stream.close();
}
}
public static void writeDocument(@NotNull Document document, @NotNull File file, String lineSeparator) throws IOException {
@@ -374,13 +370,9 @@ public class JDOMUtil {
public static void write(@NotNull Element element, @NotNull File file, @Nullable String lineSeparator) throws IOException {
FileUtil.createParentDirs(file);
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), CharsetToolkit.UTF8_CHARSET));
try {
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), CharsetToolkit.UTF8_CHARSET))) {
writeElement(element, writer, createOutputter(lineSeparator));
}
finally {
writer.close();
}
}
public static void write(@NotNull Parent element, @NotNull File file) throws IOException {
@@ -390,13 +382,9 @@ public class JDOMUtil {
public static void write(@NotNull Parent element, @NotNull File file, @NotNull String lineSeparator) throws IOException {
FileUtil.createParentDirs(file);
OutputStream stream = new BufferedOutputStream(new FileOutputStream(file));
try {
try (OutputStream stream = new BufferedOutputStream(new FileOutputStream(file))) {
write(element, stream, lineSeparator);
}
finally {
stream.close();
}
}
public static void writeDocument(@NotNull Document document, @NotNull OutputStream stream, String lineSeparator) throws IOException {
@@ -404,8 +392,7 @@ public class JDOMUtil {
}
public static void write(@NotNull Parent element, @NotNull OutputStream stream, @NotNull String lineSeparator) throws IOException {
OutputStreamWriter writer = new OutputStreamWriter(stream, CharsetToolkit.UTF8_CHARSET);
try {
try (OutputStreamWriter writer = new OutputStreamWriter(stream, CharsetToolkit.UTF8_CHARSET)) {
if (element instanceof Document) {
writeDocument((Document)element, writer, lineSeparator);
}
@@ -413,9 +400,6 @@ public class JDOMUtil {
writeElement((Element)element, writer, lineSeparator);
}
}
finally {
writer.close();
}
}
@NotNull
@@ -191,8 +191,7 @@ public class FileUtil extends FileUtilRt {
@NotNull
public static byte[] loadFileBytes(@NotNull File file) throws IOException {
byte[] bytes;
final InputStream stream = new FileInputStream(file);
try {
try (InputStream stream = new FileInputStream(file)) {
final long len = file.length();
if (len < 0) {
throw new IOException("File length reported negative, probably doesn't exist");
@@ -204,9 +203,6 @@ public class FileUtil extends FileUtilRt {
bytes = loadBytes(stream, (int)len);
}
finally {
stream.close();
}
return bytes;
}
@@ -437,19 +433,11 @@ public class FileUtil extends FileUtilRt {
private static void performCopy(@NotNull File fromFile, @NotNull File toFile, final boolean syncTimestamp) throws IOException {
if (filesEqual(fromFile, toFile)) return;
final FileOutputStream fos = openOutputStream(toFile);
try {
final FileInputStream fis = new FileInputStream(fromFile);
try {
try (FileOutputStream fos = openOutputStream(toFile)) {
try (FileInputStream fis = new FileInputStream(fromFile)) {
copy(fis, fos);
}
finally {
fis.close();
}
}
finally {
fos.close();
}
if (syncTimestamp) {
@@ -1109,13 +1097,9 @@ public class FileUtil extends FileUtilRt {
private static void writeToFile(@NotNull File file, @NotNull byte[] text, int off, int len, boolean append) throws IOException {
createParentDirs(file);
OutputStream stream = new FileOutputStream(file, append);
try {
try (OutputStream stream = new FileOutputStream(file, append)) {
stream.write(text, off, len);
}
finally {
stream.close();
}
}
@NotNull
@@ -52,13 +52,9 @@ public class JarUtil {
public static boolean containsEntry(File file, String entryPath) {
if (file.canRead()) {
try {
JarFile jarFile = new JarFile(file);
try {
try (JarFile jarFile = new JarFile(file)) {
return jarFile.getEntry(entryPath) != null;
}
finally {
jarFile.close();
}
}
catch (IOException ignored) { }
}
@@ -87,17 +83,13 @@ public class JarUtil {
private static String getJarAttributeImpl(@NotNull File file, @Nullable String entryName, @NotNull Attributes.Name attribute) {
if (file.canRead()) {
try {
JarFile jarFile = new JarFile(file);
try {
try (JarFile jarFile = new JarFile(file)) {
Manifest manifest = jarFile.getManifest();
if (manifest != null) {
Attributes attributes = entryName != null ? manifest.getAttributes(entryName) : manifest.getMainAttributes();
return attributes.getValue(attribute);
}
}
finally {
jarFile.close();
}
}
catch (IOException e) {
LOG.debug(e);
@@ -115,8 +107,7 @@ public class JarUtil {
public static Properties loadProperties(@NotNull File file, @NotNull String entryName) {
if (file.canRead()) {
try {
ZipFile zipFile = new ZipFile(file);
try {
try (ZipFile zipFile = new ZipFile(file)) {
ZipEntry entry = zipFile.getEntry(entryName);
if (entry != null) {
Properties properties = new Properties();
@@ -124,9 +115,6 @@ public class JarUtil {
return properties;
}
}
finally {
zipFile.close();
}
}
catch (IOException e) {
LOG.debug(e);
@@ -472,13 +472,9 @@ public class CharsetToolkit {
public static Charset guessEncoding(@NotNull File f, int bufferLength, @NotNull Charset defaultCharset) throws IOException {
byte[] buffer = new byte[bufferLength];
int read;
FileInputStream fis = new FileInputStream(f);
try {
try (FileInputStream fis = new FileInputStream(f)) {
read = fis.read(buffer);
}
finally {
fis.close();
}
CharsetToolkit toolkit = new CharsetToolkit(buffer, defaultCharset);
return toolkit.guessEncoding(read);
}
@@ -114,8 +114,7 @@ public class ResourceUtil {
public static String loadText(@NotNull URL url) throws IOException {
InputStream inputStream = new BufferedInputStream(URLUtil.openStream(url));
InputStreamReader reader = new InputStreamReader(inputStream, CharsetToolkit.UTF8_CHARSET);
try {
try (InputStreamReader reader = new InputStreamReader(inputStream, CharsetToolkit.UTF8_CHARSET)) {
StringBuilder text = new StringBuilder();
char[] buf = new char[5000];
while (reader.ready()) {
@@ -125,8 +124,5 @@ public class ResourceUtil {
}
return text.toString();
}
finally {
reader.close();
}
}
}
@@ -440,16 +440,12 @@ public class ConcurrentBitSet {
}
public void writeTo(@NotNull File file) throws IOException {
DataOutputStream bitSetStorage = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
try {
try (DataOutputStream bitSetStorage = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file)))) {
long[] words = toLongArray();
for (long word : words) {
bitSetStorage.writeLong(word);
}
}
finally {
bitSetStorage.close();
}
}
@NotNull
@@ -457,18 +453,14 @@ public class ConcurrentBitSet {
if (!file.exists()) {
return new ConcurrentBitSet();
}
DataInputStream bitSetStorage = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
try {
try (DataInputStream bitSetStorage = new DataInputStream(new BufferedInputStream(new FileInputStream(file)))) {
long length = file.length();
long[] words = new long[(int)(length/8)];
for (int i=0; i<words.length;i++) {
long[] words = new long[(int)(length / 8)];
for (int i = 0; i < words.length; i++) {
words[i] = bitSetStorage.readLong();
}
return new ConcurrentBitSet(words);
}
finally {
bitSetStorage.close();
}
}
private ConcurrentBitSet(@NotNull long[] words) {
@@ -111,15 +111,15 @@ public class AppendableStorageBackedByResizableMappedFile extends ResizeableMapp
}
if (myFileLength == 0) return true;
DataInputStream keysStream = new DataInputStream(new BufferedInputStream(new LimitedInputStream(new FileInputStream(getPagedFileStorage().getFile()),
myFileLength) {
@Override
public int available() {
return remainingLimit();
}
}, 32768));
try {
try (DataInputStream keysStream = new DataInputStream(
new BufferedInputStream(new LimitedInputStream(new FileInputStream(getPagedFileStorage().getFile()),
myFileLength) {
@Override
public int available() {
return remainingLimit();
}
}, 32768))) {
try {
while (true) {
Data key = descriptor.read(keysStream);
@@ -135,9 +135,6 @@ public class AppendableStorageBackedByResizableMappedFile extends ResizeableMapp
}
return true;
}
finally {
keysStream.close();
}
}
public int getCurrentLength() {
@@ -86,11 +86,8 @@ public class CompressedAppendableFile {
}
public synchronized <Data> Data read(final long addr, KeyDescriptor<Data> descriptor) throws IOException {
DataInputStream stream = getStream(addr);
try {
try (DataInputStream stream = getStream(addr)) {
return descriptor.read(stream);
} finally {
stream.close();
}
}
@@ -112,14 +109,13 @@ public class CompressedAppendableFile {
File chunkLengthFile = getChunkLengthFile();
if (chunkLengthFile.exists()) {
final DataInputStream chunkLengthStream = new DataInputStream(new BufferedInputStream(
try (DataInputStream chunkLengthStream = new DataInputStream(new BufferedInputStream(
new LimitedInputStream(new FileInputStream(chunkLengthFile), (int)chunkLengthFile.length()) {
@Override
public int available() {
return remainingLimit();
}
}, 32768));
try{
}, 32768))) {
short[] chunkLengthTable = new short[(int)(chunkLengthFile.length() / 2)];
int chunkLengthTableLength = 0;
@@ -139,28 +135,25 @@ public class CompressedAppendableFile {
if (myChunkTableLength >= FACTOR) {
long[] chunkOffsetTable = new long[myChunkTableLength / FACTOR];
long offset = 0;
for(int i = 0; i < chunkOffsetTable.length; ++i) {
for (int i = 0; i < chunkOffsetTable.length; ++i) {
int start = i * FACTOR;
for(int j = 0; j < FACTOR; ++j) {
for (int j = 0; j < FACTOR; ++j) {
offset += chunkLengthTable[start + j] & MAX_PAGE_LENGTH;
}
chunkOffsetTable[i] = offset;
}
myChunkOffsetTable = chunkOffsetTable;
if (doDebug) { // check all offsets
for(int i = 0; i < chunkLengthTableLength; ++i) {
for (int i = 0; i < chunkLengthTableLength; ++i) {
calcOffsetOfPage(i);
}
}
} else {
}
else {
myChunkOffsetTable = ArrayUtil.EMPTY_LONG_ARRAY;
}
myFileLength = calcOffsetOfPage(myChunkTableLength - 1);
} finally {
try {
chunkLengthStream.close();
} catch (IOException ignore) {}
}
}
else {
@@ -189,8 +182,7 @@ public class CompressedAppendableFile {
if (myChunkLengthTable == null) initChunkLengthTable();
assert chunkNumber < myChunkTableLength;
final DataInputStream keysStream = getChunkStream(getChunksFile(), chunkNumber);
try {
try (DataInputStream keysStream = getChunkStream(getChunksFile(), chunkNumber)) {
if (keysStream.available() > 0) {
byte[] decompressedBytes = decompress(keysStream);
if (decompressedBytes.length != myAppendBufferLength) {
@@ -198,10 +190,6 @@ public class CompressedAppendableFile {
}
return decompressedBytes;
}
} finally {
try {
keysStream.close();
} catch (IOException ignore) {}
}
assert false:"data corruption detected:"+chunkNumber + "," + myChunkTableLength;
@@ -306,17 +294,9 @@ public class CompressedAppendableFile {
myBufferPosition = (int)tempAppendFile.length();
myNextChunkBuffer = new byte[calcBufferSize(myBufferPosition)];
FileInputStream stream = new FileInputStream(tempAppendFile);
try {
try (FileInputStream stream = new FileInputStream(tempAppendFile)) {
stream.read(myNextChunkBuffer, 0, myBufferPosition);
}
finally {
try {
stream.close();
}
catch (IOException ignore) {
}
}
}
else {
myBufferPosition = 0;
@@ -382,24 +362,13 @@ public class CompressedAppendableFile {
}
protected void saveChunk(BufferExposingByteArrayOutputStream compressedChunk, long endOfFileOffset) throws IOException {
DataOutputStream stream =
new DataOutputStream(new BufferedOutputStream(new FileOutputStream(getChunksFile(), true)));
try {
try (DataOutputStream stream = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(getChunksFile(), true)))) {
stream.write(compressedChunk.getInternalBuffer(), 0, compressedChunk.size());
} finally {
try {
stream.close();
} catch (IOException ignore) {}
}
DataOutputStream chunkLengthStream =
new DataOutputStream(new BufferedOutputStream(new FileOutputStream(getChunkLengthFile(), true)));
try {
try (DataOutputStream chunkLengthStream = new DataOutputStream(
new BufferedOutputStream(new FileOutputStream(getChunkLengthFile(), true)))) {
DataInputOutputUtil.writeINT(chunkLengthStream, compressedChunk.size());
} finally {
try {
chunkLengthStream.close();
} catch (IOException ignore) {}
}
}
@@ -415,18 +384,9 @@ public class CompressedAppendableFile {
try {
saveNextChunkIfNeeded();
if (myBufferPosition != 0) {
BufferedOutputStream stream =
new BufferedOutputStream(new FileOutputStream(incompleteChunkFile));
try {
try (BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(incompleteChunkFile))) {
stream.write(myNextChunkBuffer, 0, myBufferPosition);
}
finally {
try {
stream.close();
}
catch (IOException ignore) {
}
}
} else {
incompleteChunkFile.delete();
}
@@ -140,13 +140,9 @@ public abstract class Compressor implements Closeable {
public final void addFile(@NotNull String entryName, @NotNull File file) throws IOException {
entryName = entryName(entryName);
if (accepts(entryName)) {
InputStream source = new FileInputStream(file);
try {
try (InputStream source = new FileInputStream(file)) {
writeFileEntry(entryName, source, file.length(), file.lastModified());
}
finally {
source.close();
}
}
}
@@ -150,13 +150,9 @@ public abstract class Decompressor {
InputStream inputStream = openEntryStream(entry);
try {
FileUtil.createParentDirs(outputFile);
FileOutputStream outputStream = new FileOutputStream(outputFile);
try {
try (FileOutputStream outputStream = new FileOutputStream(outputFile)) {
FileUtil.copy(inputStream, outputStream);
}
finally {
outputStream.close();
}
}
finally {
closeEntryStream(inputStream);
@@ -354,13 +354,9 @@ public class PagedFileStorage implements Forceable {
private void resizeFile(long newSize) throws IOException {
mySize = -1;
RandomAccessFile raf = new RandomAccessFile(myFile, RW);
try {
try (RandomAccessFile raf = new RandomAccessFile(myFile, RW)) {
raf.setLength(newSize);
}
finally {
raf.close();
}
mySize = newSize;
}
@@ -602,14 +602,10 @@ public class PersistentHashMap<Key, Value> extends PersistentEnumeratorDelegate<
final PersistentHashMapValueStorage.ReadResult readResult = myValueStorage.readBytes(valueOffset);
DataInputStream input = new DataInputStream(new UnsyncByteArrayInputStream(readResult.buffer));
final Value valueRead;
try {
try (DataInputStream input = new DataInputStream(new UnsyncByteArrayInputStream(readResult.buffer))) {
valueRead = myValueExternalizer.read(input);
}
finally {
input.close();
}
if (myValueStorage.performChunksCompaction(readResult.chunksCount, readResult.buffer.length)) {
long newValueOffset = myValueStorage.compactChunks(new ValueDataAppender() {
@@ -31,18 +31,10 @@ public class ReadOnlyMappedBufferWrapper extends MappedBufferWrapper {
@Override
protected MappedByteBuffer map() throws IOException {
final FileInputStream stream = new FileInputStream(myFile);
try {
final FileChannel channel = stream.getChannel();
try {
try (FileInputStream stream = new FileInputStream(myFile)) {
try (FileChannel channel = stream.getChannel()) {
return channel.map(FileChannel.MapMode.READ_ONLY, myPosition, myLength);
}
finally {
channel.close();
}
}
finally {
stream.close();
}
}
}
@@ -35,18 +35,10 @@ public class ReadWriteMappedBufferWrapper extends MappedBufferWrapper {
@Override
protected MappedByteBuffer map() throws IOException {
final RandomAccessFile file = new RandomAccessFile(myFile, RW);
try {
final FileChannel channel = file.getChannel();
try {
try (RandomAccessFile file = new RandomAccessFile(myFile, RW)) {
try (FileChannel channel = file.getChannel()) {
return channel.map(FileChannel.MapMode.READ_WRITE, myPosition, myLength);
}
finally {
channel.close();
}
}
finally {
file.close();
}
}
}
@@ -65,16 +65,9 @@ public class SourceCodeCompressor {
DEFLATER.reset();
DEFLATER.setDictionary(PRESET_BUF);
try {
DeflaterOutputStream output = null;
try {
output = new DeflaterOutputStream(OUTPUT, DEFLATER);
try (DeflaterOutputStream output = new DeflaterOutputStream(OUTPUT, DEFLATER)) {
output.write(source, off, len);
}
finally {
if (output != null) {
output.close();
}
}
}
catch (IOException e) {
return source;
@@ -99,9 +92,7 @@ public class SourceCodeCompressor {
public static byte[] decompress(final byte[] compressed, final int len, final int off) throws IOException {
INFLATER.reset();
InflaterInputStream input = null;
try {
input = new InflaterInputStream(new ByteArrayInputStream(compressed, off, len), INFLATER);
try (InflaterInputStream input = new InflaterInputStream(new ByteArrayInputStream(compressed, off, len), INFLATER)) {
final int b = input.read();
if (b == -1) {
INFLATER.setDictionary(PRESET_BUF);
@@ -116,9 +107,6 @@ public class SourceCodeCompressor {
return OUTPUT.toByteArray();
}
finally {
if (input != null) {
input.close();
}
OUTPUT.reset();
}
}
@@ -117,13 +117,9 @@ public class URLUtil {
return ThreeState.NO;
}
try {
ZipFile file = new ZipFile(paths.first);
try {
try (ZipFile file = new ZipFile(paths.first)) {
return ThreeState.fromBoolean(file.getEntry(paths.second) != null);
}
finally {
file.close();
}
}
catch (IOException e) {
return ThreeState.NO;
@@ -75,13 +75,9 @@ public class ZipUtil {
}
zos.putNextEntry(e);
if (!isDir) {
InputStream is = contentProcessor.getContent(file);
try {
try (InputStream is = contentProcessor.getContent(file)) {
FileUtilRt.copy(is, zos);
}
finally {
is.close();
}
}
zos.closeEntry();
return true;
@@ -156,8 +152,7 @@ public class ZipUtil {
@SuppressWarnings("unused")
public static boolean isZipContainsFolder(File zip) throws IOException {
ZipFile zipFile = new ZipFile(zip);
try {
try (ZipFile zipFile = new ZipFile(zip)) {
Enumeration<? extends ZipEntry> en = zipFile.entries();
while (en.hasMoreElements()) {
ZipEntry zipEntry = en.nextElement();
@@ -170,26 +165,15 @@ public class ZipUtil {
}
return false;
}
finally {
zipFile.close();
}
}
public static void compressFile(@NotNull File srcFile, @NotNull File zipFile) throws IOException {
InputStream is = new FileInputStream(srcFile);
try {
ZipOutputStream os = new ZipOutputStream(new FileOutputStream(zipFile));
try {
try (InputStream is = new FileInputStream(srcFile)) {
try (ZipOutputStream os = new ZipOutputStream(new FileOutputStream(zipFile))) {
os.putNextEntry(new ZipEntry(srcFile.getName()));
FileUtilRt.copy(is, os);
os.closeEntry();
}
finally {
os.close();
}
}
finally {
is.close();
}
}
@@ -212,13 +196,9 @@ public class ZipUtil {
}
else if (!outputFile.exists() || overwrite) {
FileUtil.createParentDirs(outputFile);
FileOutputStream os = new FileOutputStream(outputFile);
try {
try (FileOutputStream os = new FileOutputStream(outputFile)) {
FileUtilRt.copy(inputStream, os);
}
finally {
os.close();
}
}
}
finally {
@@ -87,15 +87,11 @@ public class RefCountingStorage extends AbstractStorage {
result = super.readBytes(record);
}
InflaterInputStream in = new CustomInflaterInputStream(result);
try {
try (InflaterInputStream in = new CustomInflaterInputStream(result)) {
final BufferExposingByteArrayOutputStream outputStream = new BufferExposingByteArrayOutputStream();
StreamUtil.copyStreamContent(in, outputStream);
return outputStream;
}
finally {
in.close();
}
}
private static class CustomInflaterInputStream extends InflaterInputStream {
@@ -165,13 +161,9 @@ public class RefCountingStorage extends AbstractStorage {
private void zipAndWrite(ByteArraySequence bytes, int record, boolean fixedSize) throws IOException {
BufferExposingByteArrayOutputStream s = new BufferExposingByteArrayOutputStream();
DeflaterOutputStream out = new DeflaterOutputStream(s);
try {
try (DeflaterOutputStream out = new DeflaterOutputStream(s)) {
out.write(bytes.getBytes(), bytes.getOffset(), bytes.getLength());
}
finally {
out.close();
}
synchronized (myLock) {
doWrite(record, fixedSize, s);
@@ -451,13 +451,9 @@ public class JBZipEntry implements Cloneable {
}
void doSetDataFromFile(File file) throws IOException {
InputStream input = new BufferedInputStream(new FileInputStream(file));
try {
try (InputStream input = new BufferedInputStream(new FileInputStream(file))) {
myFile.getOutputStream().putNextEntryContent(this, file.length(), input);
}
finally {
input.close();
}
}
public void writeDataTo(OutputStream output) throws IOException {
@@ -470,13 +466,9 @@ public class JBZipEntry implements Cloneable {
public byte[] getData() throws IOException {
if (size == -1) throw new IOException("no data");
final InputStream stream = getInputStream();
try {
try (InputStream stream = getInputStream()) {
return FileUtil.loadBytes(stream, (int)size);
}
finally {
stream.close();
}
}
private long calcDataOffset() throws IOException {
@@ -380,13 +380,9 @@ class JBZipOutputStream {
if (entry.getMethod() == ZipEntry.DEFLATED) {
def.setLevel(level);
final BufferExposingByteArrayOutputStream compressedBytesStream = new BufferExposingByteArrayOutputStream();
final DeflaterOutputStream stream = new DeflaterOutputStream(compressedBytesStream, def);
try {
try (DeflaterOutputStream stream = new DeflaterOutputStream(compressedBytesStream, def)) {
stream.write(bytes);
}
finally {
stream.close();
}
outputBytesLength = compressedBytesStream.size();
outputBytes = compressedBytesStream.getInternalBuffer();
}
@@ -73,11 +73,8 @@ public class ScreenReader {
Properties properties = new Properties();
for (String path : paths) {
try {
FileInputStream in = new FileInputStream(new File(path));
try {
try (FileInputStream in = new FileInputStream(new File(path))) {
properties.load(in);
} finally {
in.close();
}
}
catch (Exception ignore) {