< prev index next >

test/jdk/jdk/nio/zipfs/ZeroDate.java

Print this page




  32 import java.io.OutputStream;
  33 import java.net.URI;
  34 import java.nio.file.FileSystem;
  35 import java.nio.file.FileSystems;
  36 import java.nio.file.Files;
  37 import java.nio.file.Path;
  38 import java.nio.file.attribute.BasicFileAttributes;
  39 import java.time.Instant;
  40 import java.time.LocalDate;
  41 import java.time.LocalDateTime;
  42 import java.time.ZoneId;
  43 import java.util.Collections;
  44 import java.util.zip.ZipEntry;
  45 import java.util.zip.ZipOutputStream;
  46 
  47 /* @test
  48  * @bug 8184940 8186227 8188869
  49  * @summary JDK 9 rejects zip files where the modified day or month is 0
  50  *          or otherwise represent an invalid date, such as 1980-02-30 24:60:60
  51  * @author Liam Miller-Cushon

  52  */
  53 public class ZeroDate {
  54 
  55     public static void main(String[] args) throws Exception {
  56         // create a zip file, and read it in as a byte array
  57         Path path = Files.createTempFile("bad", ".zip");
  58         try (OutputStream os = Files.newOutputStream(path);
  59                 ZipOutputStream zos = new ZipOutputStream(os)) {
  60             ZipEntry e = new ZipEntry("x");
  61             zos.putNextEntry(e);
  62             zos.write((int) 'x');
  63         }
  64         int len = (int) Files.size(path);
  65         byte[] data = new byte[len];
  66         try (InputStream is = Files.newInputStream(path)) {
  67             is.read(data);
  68         }
  69         Files.delete(path);
  70 
  71         // year, month, day are zero




  32 import java.io.OutputStream;
  33 import java.net.URI;
  34 import java.nio.file.FileSystem;
  35 import java.nio.file.FileSystems;
  36 import java.nio.file.Files;
  37 import java.nio.file.Path;
  38 import java.nio.file.attribute.BasicFileAttributes;
  39 import java.time.Instant;
  40 import java.time.LocalDate;
  41 import java.time.LocalDateTime;
  42 import java.time.ZoneId;
  43 import java.util.Collections;
  44 import java.util.zip.ZipEntry;
  45 import java.util.zip.ZipOutputStream;
  46 
  47 /* @test
  48  * @bug 8184940 8186227 8188869
  49  * @summary JDK 9 rejects zip files where the modified day or month is 0
  50  *          or otherwise represent an invalid date, such as 1980-02-30 24:60:60
  51  * @author Liam Miller-Cushon
  52  * @modules jdk.zipfs
  53  */
  54 public class ZeroDate {
  55 
  56     public static void main(String[] args) throws Exception {
  57         // create a zip file, and read it in as a byte array
  58         Path path = Files.createTempFile("bad", ".zip");
  59         try (OutputStream os = Files.newOutputStream(path);
  60                 ZipOutputStream zos = new ZipOutputStream(os)) {
  61             ZipEntry e = new ZipEntry("x");
  62             zos.putNextEntry(e);
  63             zos.write((int) 'x');
  64         }
  65         int len = (int) Files.size(path);
  66         byte[] data = new byte[len];
  67         try (InputStream is = Files.newInputStream(path)) {
  68             is.read(data);
  69         }
  70         Files.delete(path);
  71 
  72         // year, month, day are zero


< prev index next >