-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
122 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 19 additions & 19 deletions
38
...mpo/dayon/common/squeeze/NULL_Zipper.java → .../mpo/dayon/common/squeeze/NullZipper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
package mpo.dayon.common.squeeze; | ||
|
||
import mpo.dayon.common.buffer.MemByteBuffer; | ||
|
||
public class NULL_Zipper implements Zipper { | ||
@Override | ||
public MemByteBuffer zip(MemByteBuffer unzipped) { | ||
final MemByteBuffer zipped = new MemByteBuffer(); | ||
zipped.write(unzipped.getInternal(), 0, unzipped.size()); | ||
return zipped; | ||
} | ||
|
||
@Override | ||
public MemByteBuffer unzip(MemByteBuffer zipped) { | ||
final MemByteBuffer unzipped = new MemByteBuffer(); | ||
unzipped.write(zipped.getInternal(), 0, zipped.size()); | ||
return unzipped; | ||
} | ||
} | ||
package mpo.dayon.common.squeeze; | ||
|
||
import mpo.dayon.common.buffer.MemByteBuffer; | ||
|
||
public class NullZipper implements Zipper { | ||
@Override | ||
public MemByteBuffer zip(MemByteBuffer unzipped) { | ||
final MemByteBuffer zipped = new MemByteBuffer(); | ||
zipped.write(unzipped.getInternal(), 0, unzipped.size()); | ||
return zipped; | ||
} | ||
|
||
@Override | ||
public MemByteBuffer unzip(MemByteBuffer zipped) { | ||
final MemByteBuffer unzipped = new MemByteBuffer(); | ||
unzipped.write(zipped.getInternal(), 0, zipped.size()); | ||
return unzipped; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 49 additions & 58 deletions
107
.../mpo/dayon/common/squeeze/ZIP_Zipper.java → ...a/mpo/dayon/common/squeeze/ZipZipper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,50 @@ | ||
package mpo.dayon.common.squeeze; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.util.zip.ZipEntry; | ||
import java.util.zip.ZipInputStream; | ||
import java.util.zip.ZipOutputStream; | ||
|
||
import mpo.dayon.common.buffer.MemByteBuffer; | ||
|
||
public class ZIP_Zipper implements Zipper { | ||
|
||
@Override | ||
public MemByteBuffer zip(MemByteBuffer unzipped) throws IOException { | ||
final MemByteBuffer zipped = new MemByteBuffer(); | ||
|
||
final OutputStream zip = createZipOutputStream(zipped); | ||
|
||
zip.write(unzipped.getInternal(), 0, unzipped.size()); | ||
zip.flush(); | ||
|
||
zip.close(); | ||
|
||
return zipped; | ||
} | ||
|
||
private static OutputStream createZipOutputStream(MemByteBuffer zipped) throws IOException { | ||
final ZipOutputStream zip = new ZipOutputStream(zipped); | ||
zip.putNextEntry(new ZipEntry("dirty-tiles")); | ||
return zip; | ||
} | ||
|
||
@Override | ||
public MemByteBuffer unzip(MemByteBuffer zipped) throws IOException { | ||
try (final MemByteBuffer unzipped = new MemByteBuffer()) { | ||
final InputStream unzip = createZipInputStream(zipped); | ||
|
||
final byte[] buffer = new byte[4096]; | ||
|
||
int count; | ||
while ((count = unzip.read(buffer)) > 0) { | ||
unzipped.write(buffer, 0, count); | ||
} | ||
|
||
unzip.close(); | ||
|
||
return unzipped; | ||
} | ||
} | ||
|
||
private static InputStream createZipInputStream(MemByteBuffer zipped) throws IOException { | ||
final ZipInputStream unzip = new ZipInputStream(new ByteArrayInputStream(zipped.getInternal(), 0, zipped.size())); | ||
unzip.getNextEntry(); | ||
return unzip; | ||
} | ||
|
||
package mpo.dayon.common.squeeze; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.util.zip.ZipEntry; | ||
import java.util.zip.ZipInputStream; | ||
import java.util.zip.ZipOutputStream; | ||
|
||
import mpo.dayon.common.buffer.MemByteBuffer; | ||
|
||
public class ZipZipper implements Zipper { | ||
|
||
@Override | ||
public MemByteBuffer zip(MemByteBuffer unzipped) throws IOException { | ||
final MemByteBuffer zipped = new MemByteBuffer(); | ||
final OutputStream zip = createZipOutputStream(zipped); | ||
zip.write(unzipped.getInternal(), 0, unzipped.size()); | ||
zip.flush(); | ||
zip.close(); | ||
return zipped; | ||
} | ||
|
||
private static OutputStream createZipOutputStream(MemByteBuffer zipped) throws IOException { | ||
final ZipOutputStream zip = new ZipOutputStream(zipped); | ||
zip.putNextEntry(new ZipEntry("dirty-tiles")); | ||
return zip; | ||
} | ||
|
||
@Override | ||
public MemByteBuffer unzip(MemByteBuffer zipped) throws IOException { | ||
try (final MemByteBuffer unzipped = new MemByteBuffer()) { | ||
final InputStream unzip = createZipInputStream(zipped); | ||
final byte[] buffer = new byte[4096]; | ||
int count; | ||
while ((count = unzip.read(buffer)) > 0) { | ||
unzipped.write(buffer, 0, count); | ||
} | ||
unzip.close(); | ||
return unzipped; | ||
} | ||
} | ||
|
||
private static InputStream createZipInputStream(MemByteBuffer zipped) throws IOException { | ||
final ZipInputStream unzip = new ZipInputStream(new ByteArrayInputStream(zipped.getInternal(), 0, zipped.size())); | ||
unzip.getNextEntry(); | ||
return unzip; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package mpo.dayon.common.squeeze; | ||
|
||
import mpo.dayon.common.buffer.MemByteBuffer; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class XzZipperTest { | ||
|
||
@Test | ||
void zipAndUnzip() throws IOException { | ||
// given | ||
int star = 42; | ||
MemByteBuffer origin = new MemByteBuffer(); | ||
origin.write(star); | ||
XzZipper zipper = new XzZipper(); | ||
// when | ||
final MemByteBuffer unzipped = zipper.unzip(zipper.zip(origin)); | ||
// then | ||
assertEquals(new String(origin.getInternal(), UTF_8), new String(unzipped.getInternal(), UTF_8)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package mpo.dayon.common.squeeze; | ||
|
||
import mpo.dayon.common.buffer.MemByteBuffer; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class ZipZipperTest { | ||
|
||
@Test | ||
void zipAndUnzip() throws IOException { | ||
// given | ||
int star = 42; | ||
MemByteBuffer origin = new MemByteBuffer(); | ||
origin.write(star); | ||
ZipZipper zipper = new ZipZipper(); | ||
// when | ||
final MemByteBuffer unzipped = zipper.unzip(zipper.zip(origin)); | ||
// then | ||
assertEquals(new String(origin.getInternal(), UTF_8), new String(unzipped.getInternal(), UTF_8)); | ||
} | ||
} |