-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use java.nio.file instead of java.io (#53)
* Use java.nio.file instead of java.io * Remove deprecated methods
- Loading branch information
Showing
16 changed files
with
98 additions
and
105 deletions.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,11 +12,9 @@ | |
*/ | ||
package org.eclipse.packager.deb.tests; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.time.Instant; | ||
import java.util.Optional; | ||
import java.util.function.Supplier; | ||
|
@@ -33,40 +31,40 @@ public class BinaryPackageTest { | |
@SuppressWarnings("deprecation") | ||
@Test | ||
public void test1() throws IOException, InterruptedException { | ||
final File file1 = Files.createTempFile("test-1-", ".deb").toFile(); | ||
final File file2 = Files.createTempFile("test-2-", ".deb").toFile(); | ||
final Path file1 = Files.createTempFile("test-1-", ".deb"); | ||
final Path file2 = Files.createTempFile("test-2-", ".deb"); | ||
|
||
final Instant now = Instant.now(); | ||
final Supplier<Instant> timestampProvider = () -> now; | ||
|
||
createDebFile(file1, timestampProvider); | ||
System.out.println("File: " + file1); | ||
Assertions.assertTrue(file1.exists(), "File exists"); | ||
Assertions.assertTrue(Files.exists(file1), "File exists"); | ||
|
||
Thread.sleep(1_001); // sleep for a second to make sure that a timestamp might be changed | ||
|
||
createDebFile(file2, timestampProvider); | ||
System.out.println("File: " + file2); | ||
Assertions.assertTrue(file2.exists(), "File exists"); | ||
Assertions.assertTrue(Files.exists(file2), "File exists"); | ||
|
||
final byte[] b1 = Files.readAllBytes(file1.toPath()); | ||
final byte[] b1 = Files.readAllBytes(file1); | ||
final String h1 = Hashing.md5().hashBytes(b1).toString(); | ||
final byte[] b2 = Files.readAllBytes(file2.toPath()); | ||
final byte[] b2 = Files.readAllBytes(file2); | ||
final String h2 = Hashing.md5().hashBytes(b2).toString(); | ||
System.out.println(h1); | ||
System.out.println(h2); | ||
Assertions.assertEquals(h1, h2); | ||
} | ||
|
||
private void createDebFile(final File file, final Supplier<Instant> timestampProvider) throws IOException, FileNotFoundException { | ||
private void createDebFile(final Path file, final Supplier<Instant> timestampProvider) throws IOException { | ||
final BinaryPackageControlFile packageFile = new BinaryPackageControlFile(); | ||
packageFile.setPackage("test"); | ||
packageFile.setVersion("0.0.1"); | ||
packageFile.setArchitecture("all"); | ||
packageFile.setMaintainer("Jens Reimann <[email protected]>"); | ||
packageFile.setDescription("Test package\nThis is just a test package\n\nNothing to worry about!"); | ||
|
||
try (DebianPackageWriter deb = new DebianPackageWriter(new FileOutputStream(file), packageFile, timestampProvider)) { | ||
try (DebianPackageWriter deb = new DebianPackageWriter(Files.newOutputStream(file), packageFile, timestampProvider)) { | ||
deb.addFile("Hello World\n".getBytes(), "/usr/share/foo-test/foo.txt", null, Optional.of(timestampProvider)); | ||
deb.addFile("Hello World\n".getBytes(), "/etc/foo.txt", EntryInformation.DEFAULT_FILE_CONF, Optional.of(timestampProvider)); | ||
} | ||
|
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
Oops, something went wrong.