-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix timestamp roundtripping issue (#36)
* Fix timestamp roundtripping issue * remove stray comment --------- Co-authored-by: Oscar Boykin <oboykin@netflix.com>
- Loading branch information
Showing
3 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/test/java/com/github/johnynek/jarjar/TimestampFixTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.github.johnynek.jarjar; | ||
|
||
import java.util.jar.JarEntry; | ||
import junit.framework.TestCase; | ||
import org.junit.Test; | ||
import com.github.johnynek.jarjar.util.StandaloneJarProcessor; | ||
import java.util.jar.JarOutputStream; | ||
import java.util.jar.JarInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.ByteArrayInputStream; | ||
|
||
public class TimestampFixTest extends TestCase { | ||
@Test | ||
public void testTimestampFix() throws java.io.IOException { | ||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
JarOutputStream out = new JarOutputStream(baos); | ||
JarEntry je = new JarEntry("foo.txt"); | ||
// we can only have second resolution | ||
long nowSeconds = System.currentTimeMillis() / 1000; | ||
if ((nowSeconds & 1L) == 1L) { | ||
// make sure we have an even timestamp | ||
nowSeconds -= 1L; | ||
} | ||
long startTime = (nowSeconds * 1000); | ||
je.setTime(startTime); | ||
out.putNextEntry(je); | ||
out.write(new byte[]{}); | ||
out.close(); | ||
JarInputStream in = new JarInputStream(new ByteArrayInputStream(baos.toByteArray())); | ||
je = in.getNextJarEntry(); | ||
long readTime = StandaloneJarProcessor.fixTimestamp(je.getTime()); | ||
assertEquals(startTime, readTime); | ||
} | ||
|
||
} |