Uploaded image for project: 'Maven Wagon'
  1. Maven Wagon
  2. WAGON-482

Use sparse files in HugeFileDownloadTest with Java 7

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.11
    • Fix Version/s: 3.1.0
    • Component/s: wagon-http
    • Labels:
      None

      Description

      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:

      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);
      }
      

        Attachments

          Activity

            People

            • Assignee:
              michael-o Michael Osipov
              Reporter:
              michael-o Michael Osipov
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: