mirror of
https://github.com/google/nomulus.git
synced 2025-05-05 14:37:52 +02:00
Merges the compressor creation between RyDE and Ghostryde. Note that GhostRyde will now compress with ZIP rather than the previous ZLIB. This is backwards compatible because the decompression algorithm works with either, so files created by the old version (with ZLIB) can still be opened by the new version, and vice-versa. The new file - RydeCompression.java - is a merge of the removed functions in Ghostryde.java and the RydePgpCompressionOutputStream.java. This is one of a series of CLs - each merging a single "part" of the encoding. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=205102150
48 lines
1.7 KiB
Java
48 lines
1.7 KiB
Java
// Copyright 2018 The Nomulus Authors. All Rights Reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package google.registry.rde;
|
|
|
|
import static com.google.common.truth.Truth.assertThat;
|
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
|
|
|
import com.google.common.io.ByteStreams;
|
|
import google.registry.testing.ShardableTestCase;
|
|
import java.io.ByteArrayInputStream;
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.InputStream;
|
|
import java.io.OutputStream;
|
|
import org.junit.Test;
|
|
import org.junit.runner.RunWith;
|
|
import org.junit.runners.JUnit4;
|
|
|
|
@RunWith(JUnit4.class)
|
|
public final class RydeCompressionTest extends ShardableTestCase {
|
|
|
|
@Test
|
|
public void testCompression_decompression() throws Exception {
|
|
byte[] expected = "Testing 1, 2, 3".getBytes(UTF_8);
|
|
|
|
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
try (OutputStream compressor = RydeCompression.openCompressor(output)) {
|
|
compressor.write(expected);
|
|
}
|
|
byte[] compressed = output.toByteArray();
|
|
|
|
ByteArrayInputStream input = new ByteArrayInputStream(compressed);
|
|
try (InputStream decompressor = RydeCompression.openDecompressor(input)) {
|
|
assertThat(ByteStreams.toByteArray(decompressor)).isEqualTo(expected);
|
|
}
|
|
}
|
|
}
|