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

Use sparse files in HugeFileDownloadTest with Java 7

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.11
    • 3.1.0
    • wagon-http
    • 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

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

            Dates

              Created:
              Updated:
              Resolved: