Skip to content

Commit 922c57d

Browse files
committed
1.0.0-Beta2: Implement correct file modification date time
1 parent 2d457e9 commit 922c57d

File tree

5 files changed

+45
-13
lines changed

5 files changed

+45
-13
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright 2016 Tair Sabyrgaliyev
1+
Copyright 2017 Tair Sabyrgaliyev
22

33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.

pom.xml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright 2017 Tair Sabyrgaliyev
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
217
<project xmlns="http://maven.apache.org/POM/4.0.0"
318
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
419
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
520
<modelVersion>4.0.0</modelVersion>
621

722
<groupId>io.tair</groupId>
823
<artifactId>zip</artifactId>
9-
<version>1.0.0-Beta1</version>
24+
<version>1.0.0-Beta2</version>
1025

1126
<properties>
1227
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

readme.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ See more detailed example in `io.tair.zip.ZipperInputStreamTest`
2222
== TODO
2323

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

src/main/java/io/tair/zip/ZipperInputStream.java

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 Tair Sabyrgaliyev
2+
* Copyright 2017 Tair Sabyrgaliyev
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,12 +22,7 @@
2222
import java.io.InputStream;
2323
import java.io.SequenceInputStream;
2424
import java.nio.charset.Charset;
25-
import java.util.ArrayList;
26-
import java.util.Arrays;
27-
import java.util.Collections;
28-
import java.util.Enumeration;
29-
import java.util.List;
30-
import java.util.NoSuchElementException;
25+
import java.util.*;
3126
import java.util.function.Consumer;
3227
import java.util.zip.CRC32;
3328
import java.util.zip.CheckedInputStream;
@@ -108,8 +103,30 @@ static class LocalFileHeader {
108103

109104
long compression_method = 8; // DEFLATE
110105

111-
byte[] modification_time = {0x49, (byte)0x88}
112-
, modification_date = {(byte)0xa8, 0x48}
106+
static byte[] currentDosTime(Calendar cal) {
107+
int result = cal.get(Calendar.HOUR_OF_DAY) * 2048
108+
+ cal.get(Calendar.MINUTE) * 32
109+
+ cal.get(Calendar.SECOND) / 2;
110+
111+
return new byte[] {
112+
(byte)(result >> 0),
113+
(byte)(result >> 8)
114+
};
115+
}
116+
117+
static byte[] currentDosDate(Calendar cal) {
118+
int result = (cal.get(Calendar.YEAR) - 1980) * 512
119+
+ (cal.get(Calendar.MONTH) + 1) * 32
120+
+ cal.get(Calendar.DATE);
121+
122+
return new byte[] {
123+
(byte)(result >> 0),
124+
(byte)(result >> 8)
125+
};
126+
}
127+
128+
byte[] modification_time = currentDosTime(Calendar.getInstance())
129+
, modification_date = currentDosDate(Calendar.getInstance())
113130
;
114131

115132
long crc32_checksum = 0

src/test/java/io/tair/zip/ZipperInputStreamTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 Tair Sabyrgaliyev
2+
* Copyright 2017 Tair Sabyrgaliyev
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)