Skip to content

Commit

Permalink
1.0.0-Beta2: Implement correct file modification date time
Browse files Browse the repository at this point in the history
  • Loading branch information
tsabirgaliev committed Mar 7, 2017
1 parent 2d457e9 commit 922c57d
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 13 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2016 Tair Sabyrgaliyev
Copyright 2017 Tair Sabyrgaliyev

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
17 changes: 16 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2017 Tair Sabyrgaliyev
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.tair</groupId>
<artifactId>zip</artifactId>
<version>1.0.0-Beta1</version>
<version>1.0.0-Beta2</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
2 changes: 1 addition & 1 deletion readme.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ See more detailed example in `io.tair.zip.ZipperInputStreamTest`
== TODO

[options=interactive]
- [ ] Put the correct file modification time and date
- [x] Put the correct file modification time and date
- [ ] Support ZIP64 format extensions for really BIG files
- [ ] Check duplicate file names?

Expand Down
35 changes: 26 additions & 9 deletions src/main/java/io/tair/zip/ZipperInputStream.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016 Tair Sabyrgaliyev
* Copyright 2017 Tair Sabyrgaliyev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,12 +22,7 @@
import java.io.InputStream;
import java.io.SequenceInputStream;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.*;
import java.util.function.Consumer;
import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream;
Expand Down Expand Up @@ -108,8 +103,30 @@ static class LocalFileHeader {

long compression_method = 8; // DEFLATE

byte[] modification_time = {0x49, (byte)0x88}
, modification_date = {(byte)0xa8, 0x48}
static byte[] currentDosTime(Calendar cal) {
int result = cal.get(Calendar.HOUR_OF_DAY) * 2048
+ cal.get(Calendar.MINUTE) * 32
+ cal.get(Calendar.SECOND) / 2;

return new byte[] {
(byte)(result >> 0),
(byte)(result >> 8)
};
}

static byte[] currentDosDate(Calendar cal) {
int result = (cal.get(Calendar.YEAR) - 1980) * 512
+ (cal.get(Calendar.MONTH) + 1) * 32
+ cal.get(Calendar.DATE);

return new byte[] {
(byte)(result >> 0),
(byte)(result >> 8)
};
}

byte[] modification_time = currentDosTime(Calendar.getInstance())
, modification_date = currentDosDate(Calendar.getInstance())
;

long crc32_checksum = 0
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/io/tair/zip/ZipperInputStreamTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016 Tair Sabyrgaliyev
* Copyright 2017 Tair Sabyrgaliyev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down

0 comments on commit 922c57d

Please sign in to comment.