test/java/util/zip/TestExtraTime.java

Print this page




   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /**
  25  * @test
  26  * @bug 4759491 6303183 7012868 8015666 8023713 8068790 8076641
  27  * @summary Test ZOS and ZIS timestamp in extra field correctly
  28  */
  29 
  30 import java.io.*;
  31 import java.nio.file.Files;
  32 import java.nio.file.Path;
  33 import java.nio.file.Paths;
  34 import java.nio.file.attribute.FileTime;
  35 import java.util.Arrays;
  36 import java.util.TimeZone;
  37 import java.util.concurrent.TimeUnit;
  38 import java.util.zip.ZipEntry;
  39 import java.util.zip.ZipFile;
  40 import java.util.zip.ZipInputStream;
  41 import java.util.zip.ZipOutputStream;
  42 
  43 public class TestExtraTime {
  44 
  45     public static void main(String[] args) throws Throwable{
  46 
  47         File src = new File(System.getProperty("test.src", "."), "TestExtraTime.java");
  48         if (src.exists()) {
  49             long time = src.lastModified();
  50             FileTime mtime = FileTime.from(time, TimeUnit.MILLISECONDS);
  51             FileTime atime = FileTime.from(time + 300000, TimeUnit.MILLISECONDS);
  52             FileTime ctime = FileTime.from(time - 300000, TimeUnit.MILLISECONDS);
  53             TimeZone tz = TimeZone.getTimeZone("Asia/Shanghai");
  54 
  55             for (byte[] extra : new byte[][] { null, new byte[] {1, 2, 3}}) {
  56                 test(mtime, null, null, null, extra);

  57                 // ms-dos 1980 epoch problem
  58                 test(FileTime.from(10, TimeUnit.MILLISECONDS), null, null, null, extra);



  59                 // non-default tz
  60                 test(mtime, null, null, tz, extra);
  61 
  62                 test(mtime, atime, null, null, extra);
  63                 test(mtime, null, ctime, null, extra);
  64                 test(mtime, atime, ctime, null, extra);
  65 
  66                 test(mtime, atime, null, tz, extra);
  67                 test(mtime, null, ctime, tz, extra);
  68                 test(mtime, atime, ctime, tz, extra);
  69             }
  70         }
  71 
  72         testNullHandling();
  73         testTagOnlyHandling();
  74         testTimeConversions();
  75     }
  76 
  77     static void test(FileTime mtime, FileTime atime, FileTime ctime,
  78                      TimeZone tz, byte[] extra) throws Throwable {




   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /**
  25  * @test
  26  * @bug 4759491 6303183 7012868 8015666 8023713 8068790 8076641 8075526
  27  * @summary Test ZOS and ZIS timestamp in extra field correctly
  28  */
  29 
  30 import java.io.*;
  31 import java.nio.file.Files;
  32 import java.nio.file.Path;
  33 import java.nio.file.Paths;
  34 import java.nio.file.attribute.FileTime;
  35 import java.util.Arrays;
  36 import java.util.TimeZone;
  37 import java.util.concurrent.TimeUnit;
  38 import java.util.zip.ZipEntry;
  39 import java.util.zip.ZipFile;
  40 import java.util.zip.ZipInputStream;
  41 import java.util.zip.ZipOutputStream;
  42 
  43 public class TestExtraTime {
  44 
  45     public static void main(String[] args) throws Throwable{
  46 
  47         File src = new File(System.getProperty("test.src", "."), "TestExtraTime.java");
  48         if (src.exists()) {
  49             long time = src.lastModified();
  50             FileTime mtime = FileTime.from(time, TimeUnit.MILLISECONDS);
  51             FileTime atime = FileTime.from(time + 300000, TimeUnit.MILLISECONDS);
  52             FileTime ctime = FileTime.from(time - 300000, TimeUnit.MILLISECONDS);
  53             TimeZone tz = TimeZone.getTimeZone("Asia/Shanghai");
  54 
  55             for (byte[] extra : new byte[][] { null, new byte[] {1, 2, 3}}) {
  56                 test(mtime, null, null, null, extra);
  57 
  58                 // ms-dos 1980 epoch problem
  59                 test(FileTime.from(10, TimeUnit.MILLISECONDS), null, null, null, extra);
  60                 // negative epoch time
  61                 test(FileTime.from(-100, TimeUnit.DAYS), null, null, null, extra);
  62 
  63                 // non-default tz
  64                 test(mtime, null, null, tz, extra);
  65 
  66                 test(mtime, atime, null, null, extra);
  67                 test(mtime, null, ctime, null, extra);
  68                 test(mtime, atime, ctime, null, extra);
  69 
  70                 test(mtime, atime, null, tz, extra);
  71                 test(mtime, null, ctime, tz, extra);
  72                 test(mtime, atime, ctime, tz, extra);
  73             }
  74         }
  75 
  76         testNullHandling();
  77         testTagOnlyHandling();
  78         testTimeConversions();
  79     }
  80 
  81     static void test(FileTime mtime, FileTime atime, FileTime ctime,
  82                      TimeZone tz, byte[] extra) throws Throwable {