Michael Osipov created WAGON-482: ------------------------------------ Summary: Use sparse files in HugeFileDownloadTest with Java 7 Key: WAGON-482 URL: https://issues.apache.org/jira/browse/WAGON-482 Project: Maven Wagon Issue Type: Improvement Components: wagon-http Affects Versions: 2.11 Reporter: Michael Osipov Assignee: Michael Osipov
Unfortunately, {{RandomAccessFile}} does not create sparse files on Windows with seek/position, it requires a specific flag set with NTFS. Luckily, NIO.2 supports this. File creation for 4 GiB will be tens of milliseconds. Use this snippet as soon as we move to Java 7: {code:java} Path tempDirectory = Files.createTempDirectory("jetty"); final ByteBuffer buf = ByteBuffer.allocate(4).putInt(2); buf.rewind(); final OpenOption[] options = { StandardOpenOption.WRITE, StandardOpenOption.CREATE_NEW , StandardOpenOption.SPARSE }; final Path hugeFile = tempDirectory.resolve("hugefile.txt"); try (final SeekableByteChannel channel = Files.newByteChannel(hugeFile, options);) { channel.position(HUGE_FILE_SIZE); channel.write(buf); } {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332)