Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileOutputStream;
- import java.nio.charset.Charset;
- import java.nio.charset.StandardCharsets;
- import java.util.zip.CRC32;
- import java.util.zip.ZipEntry;
- import java.util.zip.ZipOutputStream;
- public final class Zip
- {
- private static final byte[] DATA = "\uFEFFとんかつを作るにはな、こうやって油の中に指をアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアアーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥".getBytes(StandardCharsets.UTF_16LE);
- private static final CRC32 CRC = new CRC32();
- public static void main(String argv[]) throws Exception
- {
- ZipOutputStream oz = createZip("TEST.ZIP");
- addEntry(oz, "♥♥♥♥♥♥♥♥.TXT", DATA);
- oz.close();
- }
- private static ZipOutputStream createZip(String file) throws Exception
- {
- return createZip(file, null);
- }
- private static ZipOutputStream createZip(String file, Charset filenameEncoding) throws Exception
- {
- File f = new File(file);
- FileOutputStream of = new FileOutputStream(f);
- ZipOutputStream oz = (filenameEncoding != null) ? new ZipOutputStream(of, filenameEncoding) : new ZipOutputStream(of);
- oz.setMethod(ZipOutputStream.STORED);
- return oz;
- }
- private static void addEntry(ZipOutputStream oz, String name, byte[] data) throws Exception
- {
- ZipEntry e = new ZipEntry(name);
- e.setSize(data.length);
- CRC.reset();
- CRC.update(data);
- e.setCrc(CRC.getValue());
- oz.putNextEntry(e);
- oz.write(data);
- CRC.reset();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement