[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [metrics-lib/release] Change back how we treat xz-compressed files.
commit d4bb28525f550ea72ab396f24d4fc101e9f48eae
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Thu Apr 30 17:08:44 2020 +0200
Change back how we treat xz-compressed files.
It seemed like a good idea to decompress xz-compressed files before
handing over decompressed bytes to descriptor implementations.
However, our web logs expect descriptor bytes to be in compressed
form, and now they're unhappy about receiving uncompressed bytes.
Changing this back and teaching OnionPerf analysis files to expect
compressed bytes, too. Found by running CollecTor's unit tests.
---
CHANGELOG.md | 4 ++++
.../org/torproject/descriptor/impl/DescriptorReaderImpl.java | 2 --
.../descriptor/onionperf/OnionPerfAnalysisConverter.java | 12 +++++++++++-
.../descriptor/onionperf/OnionPerfAnalysisConverterTest.java | 5 +----
4 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 682980b..8fbc4bd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
# Changes in version 2.??.? - 2020-??-??
+ * Minor changes
+ - Change back how we treat xz-compressed files by leaving
+ decompression to descriptor implementations.
+
# Changes in version 2.12.0 - 2020-04-30
diff --git a/src/main/java/org/torproject/descriptor/impl/DescriptorReaderImpl.java b/src/main/java/org/torproject/descriptor/impl/DescriptorReaderImpl.java
index 0da32ad..8ec04a5 100644
--- a/src/main/java/org/torproject/descriptor/impl/DescriptorReaderImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/DescriptorReaderImpl.java
@@ -330,8 +330,6 @@ public class DescriptorReaderImpl implements DescriptorReader {
InputStream is = fis;
if (file.getName().endsWith(".gz")) {
is = new GzipCompressorInputStream(fis);
- } else if (file.getName().endsWith(".xz")) {
- is = new XZCompressorInputStream(fis);
}
byte[] rawDescriptorBytes = IOUtils.toByteArray(is);
if (rawDescriptorBytes.length > 0) {
diff --git a/src/main/java/org/torproject/descriptor/onionperf/OnionPerfAnalysisConverter.java b/src/main/java/org/torproject/descriptor/onionperf/OnionPerfAnalysisConverter.java
index 1f9b1f8..18adf8c 100644
--- a/src/main/java/org/torproject/descriptor/onionperf/OnionPerfAnalysisConverter.java
+++ b/src/main/java/org/torproject/descriptor/onionperf/OnionPerfAnalysisConverter.java
@@ -7,8 +7,13 @@ import org.torproject.descriptor.Descriptor;
import org.torproject.descriptor.DescriptorParseException;
import org.torproject.descriptor.impl.TorperfResultImpl;
+import org.apache.commons.compress.compressors.xz.XZCompressorInputStream;
+import org.apache.commons.compress.utils.IOUtils;
+
+import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -66,8 +71,13 @@ public class OnionPerfAnalysisConverter {
public List<Descriptor> asTorperfResults() throws DescriptorParseException {
ParsedOnionPerfAnalysis parsedOnionPerfAnalysis;
try {
- parsedOnionPerfAnalysis = ParsedOnionPerfAnalysis.fromBytes(
+ InputStream compressedInputStream = new ByteArrayInputStream(
this.rawDescriptorBytes);
+ InputStream decompressedInputStream = new XZCompressorInputStream(
+ compressedInputStream);
+ byte[] decompressedBytes = IOUtils.toByteArray(decompressedInputStream);
+ parsedOnionPerfAnalysis = ParsedOnionPerfAnalysis.fromBytes(
+ decompressedBytes);
} catch (IOException ioException) {
throw new DescriptorParseException("Ran into an I/O error while "
+ "attempting to parse an OnionPerf analysis document.",
diff --git a/src/test/java/org/torproject/descriptor/onionperf/OnionPerfAnalysisConverterTest.java b/src/test/java/org/torproject/descriptor/onionperf/OnionPerfAnalysisConverterTest.java
index d840dd2..c921a2d 100644
--- a/src/test/java/org/torproject/descriptor/onionperf/OnionPerfAnalysisConverterTest.java
+++ b/src/test/java/org/torproject/descriptor/onionperf/OnionPerfAnalysisConverterTest.java
@@ -10,7 +10,6 @@ import org.torproject.descriptor.Descriptor;
import org.torproject.descriptor.DescriptorParseException;
import org.torproject.descriptor.TorperfResult;
-import org.apache.commons.compress.compressors.xz.XZCompressorInputStream;
import org.apache.commons.compress.utils.IOUtils;
import org.junit.Test;
@@ -88,9 +87,7 @@ public class OnionPerfAnalysisConverterTest {
assertNotNull(resouce);
InputStream compressedInputStream = resouce.openStream();
assertNotNull(compressedInputStream);
- InputStream uncompressedInputStream = new XZCompressorInputStream(
- compressedInputStream);
- byte[] rawDescriptorBytes = IOUtils.toByteArray(uncompressedInputStream);
+ byte[] rawDescriptorBytes = IOUtils.toByteArray(compressedInputStream);
OnionPerfAnalysisConverter onionPerfAnalysisConverter
= new OnionPerfAnalysisConverter(rawDescriptorBytes, null);
for (Descriptor descriptor
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits