Rename FileChannelDataBlock to FileDataBlock

Rename the internal `FileChannelDataBlock` to `FileDataBlock` since we
want to fallback to a `RandomAccessFile` when a thread is interrupted.

See gh-40096
This commit is contained in:
Phillip Webb 2024-04-16 11:18:48 -07:00
parent 778c528281
commit 4203e1f2fa
7 changed files with 67 additions and 66 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,6 +16,7 @@
package org.springframework.boot.loader.zip; package org.springframework.boot.loader.zip;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.ClosedByInterruptException; import java.nio.channels.ClosedByInterruptException;
@ -29,14 +30,14 @@ import java.util.function.Supplier;
import org.springframework.boot.loader.log.DebugLogger; import org.springframework.boot.loader.log.DebugLogger;
/** /**
* Reference counted {@link DataBlock} implementation backed by a {@link FileChannel} with * Reference counted {@link DataBlock} implementation backed by a {@link File} with
* support for slicing. * support for slicing.
* *
* @author Phillip Webb * @author Phillip Webb
*/ */
class FileChannelDataBlock implements CloseableDataBlock { class FileDataBlock implements CloseableDataBlock {
private static final DebugLogger debug = DebugLogger.get(FileChannelDataBlock.class); private static final DebugLogger debug = DebugLogger.get(FileDataBlock.class);
static Tracker tracker; static Tracker tracker;
@ -46,13 +47,13 @@ class FileChannelDataBlock implements CloseableDataBlock {
private final long size; private final long size;
FileChannelDataBlock(Path path) throws IOException { FileDataBlock(Path path) throws IOException {
this.channel = new ManagedFileChannel(path); this.channel = new ManagedFileChannel(path);
this.offset = 0; this.offset = 0;
this.size = Files.size(path); this.size = Files.size(path);
} }
FileChannelDataBlock(ManagedFileChannel channel, long offset, long size) { FileDataBlock(ManagedFileChannel channel, long offset, long size) {
this.channel = channel; this.channel = channel;
this.offset = offset; this.offset = offset;
this.size = size; this.size = size;
@ -115,26 +116,26 @@ class FileChannelDataBlock implements CloseableDataBlock {
} }
/** /**
* Return a new {@link FileChannelDataBlock} slice providing access to a subset of the * Return a new {@link FileDataBlock} slice providing access to a subset of the data.
* data. The caller is responsible for calling {@link #open()} and {@link #close()} on * The caller is responsible for calling {@link #open()} and {@link #close()} on the
* the returned block. * returned block.
* @param offset the start offset for the slice relative to this block * @param offset the start offset for the slice relative to this block
* @return a new {@link FileChannelDataBlock} instance * @return a new {@link FileDataBlock} instance
* @throws IOException on I/O error * @throws IOException on I/O error
*/ */
FileChannelDataBlock slice(long offset) throws IOException { FileDataBlock slice(long offset) throws IOException {
return slice(offset, this.size - offset); return slice(offset, this.size - offset);
} }
/** /**
* Return a new {@link FileChannelDataBlock} slice providing access to a subset of the * Return a new {@link FileDataBlock} slice providing access to a subset of the data.
* data. The caller is responsible for calling {@link #open()} and {@link #close()} on * The caller is responsible for calling {@link #open()} and {@link #close()} on the
* the returned block. * returned block.
* @param offset the start offset for the slice relative to this block * @param offset the start offset for the slice relative to this block
* @param size the size of the new slice * @param size the size of the new slice
* @return a new {@link FileChannelDataBlock} instance * @return a new {@link FileDataBlock} instance
*/ */
FileChannelDataBlock slice(long offset, long size) { FileDataBlock slice(long offset, long size) {
if (offset == 0 && size == this.size) { if (offset == 0 && size == this.size) {
return this; return this;
} }
@ -145,7 +146,7 @@ class FileChannelDataBlock implements CloseableDataBlock {
throw new IllegalArgumentException("Size must not be negative and must be within bounds"); throw new IllegalArgumentException("Size must not be negative and must be within bounds");
} }
debug.log("Slicing %s at %s with size %s", this.channel, offset, size); debug.log("Slicing %s at %s with size %s", this.channel, offset, size);
return new FileChannelDataBlock(this.channel, this.offset + offset, size); return new FileDataBlock(this.channel, this.offset + offset, size);
} }
/** /**

View File

@ -74,7 +74,7 @@ public final class ZipContent implements Closeable {
private final Kind kind; private final Kind kind;
private final FileChannelDataBlock data; private final FileDataBlock data;
private final long centralDirectoryPos; private final long centralDirectoryPos;
@ -96,7 +96,7 @@ public final class ZipContent implements Closeable {
private SoftReference<Map<Class<?>, Object>> info; private SoftReference<Map<Class<?>, Object>> info;
private ZipContent(Source source, Kind kind, FileChannelDataBlock data, long centralDirectoryPos, long commentPos, private ZipContent(Source source, Kind kind, FileDataBlock data, long centralDirectoryPos, long commentPos,
long commentLength, int[] lookupIndexes, int[] nameHashLookups, int[] relativeCentralDirectoryOffsetLookups, long commentLength, int[] lookupIndexes, int[] nameHashLookups, int[] relativeCentralDirectoryOffsetLookups,
NameOffsetLookups nameOffsetLookups, boolean hasJarSignatureFile) { NameOffsetLookups nameOffsetLookups, boolean hasJarSignatureFile) {
this.source = source; this.source = source;
@ -449,7 +449,7 @@ public final class ZipContent implements Closeable {
private final Source source; private final Source source;
private final FileChannelDataBlock data; private final FileDataBlock data;
private final long centralDirectoryPos; private final long centralDirectoryPos;
@ -463,8 +463,7 @@ public final class ZipContent implements Closeable {
private int cursor; private int cursor;
private Loader(Source source, Entry directoryEntry, FileChannelDataBlock data, long centralDirectoryPos, private Loader(Source source, Entry directoryEntry, FileDataBlock data, long centralDirectoryPos, int maxSize) {
int maxSize) {
this.source = source; this.source = source;
this.data = data; this.data = data;
this.centralDirectoryPos = centralDirectoryPos; this.centralDirectoryPos = centralDirectoryPos;
@ -561,7 +560,7 @@ public final class ZipContent implements Closeable {
private static ZipContent loadNonNested(Source source) throws IOException { private static ZipContent loadNonNested(Source source) throws IOException {
debug.log("Loading non-nested zip '%s'", source.path()); debug.log("Loading non-nested zip '%s'", source.path());
return openAndLoad(source, Kind.ZIP, new FileChannelDataBlock(source.path())); return openAndLoad(source, Kind.ZIP, new FileDataBlock(source.path()));
} }
private static ZipContent loadNestedZip(Source source, Entry entry) throws IOException { private static ZipContent loadNestedZip(Source source, Entry entry) throws IOException {
@ -573,7 +572,7 @@ public final class ZipContent implements Closeable {
return openAndLoad(source, Kind.NESTED_ZIP, entry.getContent()); return openAndLoad(source, Kind.NESTED_ZIP, entry.getContent());
} }
private static ZipContent openAndLoad(Source source, Kind kind, FileChannelDataBlock data) throws IOException { private static ZipContent openAndLoad(Source source, Kind kind, FileDataBlock data) throws IOException {
try { try {
data.open(); data.open();
return loadContent(source, kind, data); return loadContent(source, kind, data);
@ -584,7 +583,7 @@ public final class ZipContent implements Closeable {
} }
} }
private static ZipContent loadContent(Source source, Kind kind, FileChannelDataBlock data) throws IOException { private static ZipContent loadContent(Source source, Kind kind, FileDataBlock data) throws IOException {
ZipEndOfCentralDirectoryRecord.Located locatedEocd = ZipEndOfCentralDirectoryRecord.load(data); ZipEndOfCentralDirectoryRecord.Located locatedEocd = ZipEndOfCentralDirectoryRecord.load(data);
ZipEndOfCentralDirectoryRecord eocd = locatedEocd.endOfCentralDirectoryRecord(); ZipEndOfCentralDirectoryRecord eocd = locatedEocd.endOfCentralDirectoryRecord();
long eocdPos = locatedEocd.pos(); long eocdPos = locatedEocd.pos();
@ -634,7 +633,7 @@ public final class ZipContent implements Closeable {
* @return the offset within the data where the archive begins * @return the offset within the data where the archive begins
* @throws IOException on I/O error * @throws IOException on I/O error
*/ */
private static long getStartOfZipContent(FileChannelDataBlock data, ZipEndOfCentralDirectoryRecord eocd, private static long getStartOfZipContent(FileDataBlock data, ZipEndOfCentralDirectoryRecord eocd,
Zip64EndOfCentralDirectoryRecord zip64Eocd) throws IOException { Zip64EndOfCentralDirectoryRecord zip64Eocd) throws IOException {
long specifiedOffsetToStartOfCentralDirectory = (zip64Eocd != null) long specifiedOffsetToStartOfCentralDirectory = (zip64Eocd != null)
? zip64Eocd.offsetToStartOfCentralDirectory() : eocd.offsetToStartOfCentralDirectory(); ? zip64Eocd.offsetToStartOfCentralDirectory() : eocd.offsetToStartOfCentralDirectory();
@ -699,7 +698,7 @@ public final class ZipContent implements Closeable {
private volatile String name; private volatile String name;
private volatile FileChannelDataBlock content; private volatile FileDataBlock content;
/** /**
* Create a new {@link Entry} instance. * Create a new {@link Entry} instance.
@ -789,13 +788,13 @@ public final class ZipContent implements Closeable {
* @throws IOException on I/O error * @throws IOException on I/O error
*/ */
public CloseableDataBlock openContent() throws IOException { public CloseableDataBlock openContent() throws IOException {
FileChannelDataBlock content = getContent(); FileDataBlock content = getContent();
content.open(); content.open();
return content; return content;
} }
private FileChannelDataBlock getContent() throws IOException { private FileDataBlock getContent() throws IOException {
FileChannelDataBlock content = this.content; FileDataBlock content = this.content;
if (content == null) { if (content == null) {
int pos = this.centralRecord.offsetToLocalHeader(); int pos = this.centralRecord.offsetToLocalHeader();
checkNotZip64Extended(pos); checkNotZip64Extended(pos);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -25,8 +25,8 @@ import java.lang.annotation.Target;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
/** /**
* Annotation that can be added to tests to assert that {@link FileChannelDataBlock} files * Annotation that can be added to tests to assert that {@link FileDataBlock} files are
* are not left open. * not left open.
* *
* @author Phillip Webb * @author Phillip Webb
*/ */

View File

@ -31,7 +31,7 @@ import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.api.extension.ExtensionContext;
import org.springframework.boot.loader.ref.DefaultCleanerTracking; import org.springframework.boot.loader.ref.DefaultCleanerTracking;
import org.springframework.boot.loader.zip.FileChannelDataBlock.Tracker; import org.springframework.boot.loader.zip.FileDataBlock.Tracker;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -45,14 +45,14 @@ class AssertFileChannelDataBlocksClosedExtension implements BeforeEachCallback,
@Override @Override
public void beforeEach(ExtensionContext context) throws Exception { public void beforeEach(ExtensionContext context) throws Exception {
tracker.clear(); tracker.clear();
FileChannelDataBlock.tracker = tracker; FileDataBlock.tracker = tracker;
DefaultCleanerTracking.set(tracker::addedCleanable); DefaultCleanerTracking.set(tracker::addedCleanable);
} }
@Override @Override
public void afterEach(ExtensionContext context) throws Exception { public void afterEach(ExtensionContext context) throws Exception {
tracker.assertAllClosed(); tracker.assertAllClosed();
FileChannelDataBlock.tracker = null; FileDataBlock.tracker = null;
} }
private static final class OpenFilesTracker implements Tracker { private static final class OpenFilesTracker implements Tracker {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,7 +16,7 @@
package org.springframework.boot.loader.zip; package org.springframework.boot.loader.zip;
import org.springframework.boot.loader.zip.FileChannelDataBlock.ManagedFileChannel; import org.springframework.boot.loader.zip.FileDataBlock.ManagedFileChannel;
/** /**
* Test access to {@link ManagedFileChannel} details. * Test access to {@link ManagedFileChannel} details.
@ -28,6 +28,6 @@ public final class FileChannelDataBlockManagedFileChannel {
private FileChannelDataBlockManagedFileChannel() { private FileChannelDataBlockManagedFileChannel() {
} }
public static int BUFFER_SIZE = FileChannelDataBlock.ManagedFileChannel.BUFFER_SIZE; public static int BUFFER_SIZE = FileDataBlock.ManagedFileChannel.BUFFER_SIZE;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -28,17 +28,17 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir; import org.junit.jupiter.api.io.TempDir;
import org.springframework.boot.loader.zip.FileChannelDataBlock.Tracker; import org.springframework.boot.loader.zip.FileDataBlock.Tracker;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
/** /**
* Tests for {@link FileChannelDataBlock}. * Tests for {@link FileDataBlock}.
* *
* @author Phillip Webb * @author Phillip Webb
*/ */
class FileChannelDataBlockTests { class FileDataBlockTests {
private static final byte[] CONTENT = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 }; private static final byte[] CONTENT = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 };
@ -55,19 +55,19 @@ class FileChannelDataBlockTests {
@AfterEach @AfterEach
void resetTracker() { void resetTracker() {
FileChannelDataBlock.tracker = null; FileDataBlock.tracker = null;
} }
@Test @Test
void sizeReturnsFileSize() throws IOException { void sizeReturnsFileSize() throws IOException {
try (FileChannelDataBlock block = createAndOpenBlock()) { try (FileDataBlock block = createAndOpenBlock()) {
assertThat(block.size()).isEqualTo(CONTENT.length); assertThat(block.size()).isEqualTo(CONTENT.length);
} }
} }
@Test @Test
void readReadsFile() throws IOException { void readReadsFile() throws IOException {
try (FileChannelDataBlock block = createAndOpenBlock()) { try (FileDataBlock block = createAndOpenBlock()) {
ByteBuffer buffer = ByteBuffer.allocate(CONTENT.length); ByteBuffer buffer = ByteBuffer.allocate(CONTENT.length);
assertThat(block.read(buffer, 0)).isEqualTo(6); assertThat(block.read(buffer, 0)).isEqualTo(6);
assertThat(buffer.array()).containsExactly(CONTENT); assertThat(buffer.array()).containsExactly(CONTENT);
@ -76,7 +76,8 @@ class FileChannelDataBlockTests {
@Test @Test
void readReadsFileWhenThreadHasBeenInterrupted() throws IOException { void readReadsFileWhenThreadHasBeenInterrupted() throws IOException {
try (FileChannelDataBlock block = createAndOpenBlock()) { Files.write(this.tempFile.toPath(), CONTENT);
try (FileDataBlock block = createAndOpenBlock()) {
ByteBuffer buffer = ByteBuffer.allocate(CONTENT.length); ByteBuffer buffer = ByteBuffer.allocate(CONTENT.length);
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
assertThat(block.read(buffer, 0)).isEqualTo(6); assertThat(block.read(buffer, 0)).isEqualTo(6);
@ -89,7 +90,7 @@ class FileChannelDataBlockTests {
@Test @Test
void readDoesNotReadPastEndOfFile() throws IOException { void readDoesNotReadPastEndOfFile() throws IOException {
try (FileChannelDataBlock block = createAndOpenBlock()) { try (FileDataBlock block = createAndOpenBlock()) {
ByteBuffer buffer = ByteBuffer.allocate(CONTENT.length); ByteBuffer buffer = ByteBuffer.allocate(CONTENT.length);
assertThat(block.read(buffer, 2)).isEqualTo(4); assertThat(block.read(buffer, 2)).isEqualTo(4);
assertThat(buffer.array()).containsExactly(0x02, 0x03, 0x04, 0x05, 0x0, 0x0); assertThat(buffer.array()).containsExactly(0x02, 0x03, 0x04, 0x05, 0x0, 0x0);
@ -98,7 +99,7 @@ class FileChannelDataBlockTests {
@Test @Test
void readWhenPosAtSizeReturnsMinusOne() throws IOException { void readWhenPosAtSizeReturnsMinusOne() throws IOException {
try (FileChannelDataBlock block = createAndOpenBlock()) { try (FileDataBlock block = createAndOpenBlock()) {
ByteBuffer buffer = ByteBuffer.allocate(CONTENT.length); ByteBuffer buffer = ByteBuffer.allocate(CONTENT.length);
assertThat(block.read(buffer, 6)).isEqualTo(-1); assertThat(block.read(buffer, 6)).isEqualTo(-1);
} }
@ -106,7 +107,7 @@ class FileChannelDataBlockTests {
@Test @Test
void readWhenPosOverSizeReturnsMinusOne() throws IOException { void readWhenPosOverSizeReturnsMinusOne() throws IOException {
try (FileChannelDataBlock block = createAndOpenBlock()) { try (FileDataBlock block = createAndOpenBlock()) {
ByteBuffer buffer = ByteBuffer.allocate(CONTENT.length); ByteBuffer buffer = ByteBuffer.allocate(CONTENT.length);
assertThat(block.read(buffer, 7)).isEqualTo(-1); assertThat(block.read(buffer, 7)).isEqualTo(-1);
} }
@ -114,7 +115,7 @@ class FileChannelDataBlockTests {
@Test @Test
void readWhenPosIsNegativeThrowsException() throws IOException { void readWhenPosIsNegativeThrowsException() throws IOException {
try (FileChannelDataBlock block = createAndOpenBlock()) { try (FileDataBlock block = createAndOpenBlock()) {
ByteBuffer buffer = ByteBuffer.allocate(CONTENT.length); ByteBuffer buffer = ByteBuffer.allocate(CONTENT.length);
assertThatIllegalArgumentException().isThrownBy(() -> block.read(buffer, -1)); assertThatIllegalArgumentException().isThrownBy(() -> block.read(buffer, -1));
} }
@ -122,7 +123,7 @@ class FileChannelDataBlockTests {
@Test @Test
void sliceWhenOffsetIsNegativeThrowsException() throws IOException { void sliceWhenOffsetIsNegativeThrowsException() throws IOException {
try (FileChannelDataBlock block = createAndOpenBlock()) { try (FileDataBlock block = createAndOpenBlock()) {
assertThatIllegalArgumentException().isThrownBy(() -> block.slice(-1, 0)) assertThatIllegalArgumentException().isThrownBy(() -> block.slice(-1, 0))
.withMessage("Offset must not be negative"); .withMessage("Offset must not be negative");
} }
@ -130,7 +131,7 @@ class FileChannelDataBlockTests {
@Test @Test
void sliceWhenSizeIsNegativeThrowsException() throws IOException { void sliceWhenSizeIsNegativeThrowsException() throws IOException {
try (FileChannelDataBlock block = createAndOpenBlock()) { try (FileDataBlock block = createAndOpenBlock()) {
assertThatIllegalArgumentException().isThrownBy(() -> block.slice(0, -1)) assertThatIllegalArgumentException().isThrownBy(() -> block.slice(0, -1))
.withMessage("Size must not be negative and must be within bounds"); .withMessage("Size must not be negative and must be within bounds");
} }
@ -138,7 +139,7 @@ class FileChannelDataBlockTests {
@Test @Test
void sliceWhenSizeIsOutOfBoundsThrowsException() throws IOException { void sliceWhenSizeIsOutOfBoundsThrowsException() throws IOException {
try (FileChannelDataBlock block = createAndOpenBlock()) { try (FileDataBlock block = createAndOpenBlock()) {
assertThatIllegalArgumentException().isThrownBy(() -> block.slice(2, 5)) assertThatIllegalArgumentException().isThrownBy(() -> block.slice(2, 5))
.withMessage("Size must not be negative and must be within bounds"); .withMessage("Size must not be negative and must be within bounds");
} }
@ -146,7 +147,7 @@ class FileChannelDataBlockTests {
@Test @Test
void sliceReturnsSlice() throws IOException { void sliceReturnsSlice() throws IOException {
try (FileChannelDataBlock slice = createAndOpenBlock().slice(1, 4)) { try (FileDataBlock slice = createAndOpenBlock().slice(1, 4)) {
assertThat(slice.size()).isEqualTo(4); assertThat(slice.size()).isEqualTo(4);
ByteBuffer buffer = ByteBuffer.allocate(4); ByteBuffer buffer = ByteBuffer.allocate(4);
assertThat(slice.read(buffer, 0)).isEqualTo(4); assertThat(slice.read(buffer, 0)).isEqualTo(4);
@ -157,8 +158,8 @@ class FileChannelDataBlockTests {
@Test @Test
void openAndCloseHandleReferenceCounting() throws IOException { void openAndCloseHandleReferenceCounting() throws IOException {
TestTracker tracker = new TestTracker(); TestTracker tracker = new TestTracker();
FileChannelDataBlock.tracker = tracker; FileDataBlock.tracker = tracker;
FileChannelDataBlock block = createBlock(); FileDataBlock block = createBlock();
assertThat(block).extracting("channel.referenceCount").isEqualTo(0); assertThat(block).extracting("channel.referenceCount").isEqualTo(0);
tracker.assertOpenCloseCounts(0, 0); tracker.assertOpenCloseCounts(0, 0);
block.open(); block.open();
@ -184,9 +185,9 @@ class FileChannelDataBlockTests {
@Test @Test
void openAndCloseSliceHandleReferenceCounting() throws IOException { void openAndCloseSliceHandleReferenceCounting() throws IOException {
TestTracker tracker = new TestTracker(); TestTracker tracker = new TestTracker();
FileChannelDataBlock.tracker = tracker; FileDataBlock.tracker = tracker;
FileChannelDataBlock block = createBlock(); FileDataBlock block = createBlock();
FileChannelDataBlock slice = block.slice(1, 4); FileDataBlock slice = block.slice(1, 4);
assertThat(block).extracting("channel.referenceCount").isEqualTo(0); assertThat(block).extracting("channel.referenceCount").isEqualTo(0);
tracker.assertOpenCloseCounts(0, 0); tracker.assertOpenCloseCounts(0, 0);
block.open(); block.open();
@ -215,14 +216,14 @@ class FileChannelDataBlockTests {
tracker.assertOpenCloseCounts(2, 2); tracker.assertOpenCloseCounts(2, 2);
} }
private FileChannelDataBlock createAndOpenBlock() throws IOException { private FileDataBlock createAndOpenBlock() throws IOException {
FileChannelDataBlock block = createBlock(); FileDataBlock block = createBlock();
block.open(); block.open();
return block; return block;
} }
private FileChannelDataBlock createBlock() throws IOException { private FileDataBlock createBlock() throws IOException {
return new FileChannelDataBlock(this.tempFile.toPath()); return new FileDataBlock(this.tempFile.toPath());
} }
static class TestTracker implements Tracker { static class TestTracker implements Tracker {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -58,7 +58,7 @@ class VirtualZipDataBlockTests {
@Test @Test
void createContainsValidZipContent() throws IOException { void createContainsValidZipContent() throws IOException {
FileChannelDataBlock data = new FileChannelDataBlock(this.file.toPath()); FileDataBlock data = new FileDataBlock(this.file.toPath());
data.open(); data.open();
List<ZipCentralDirectoryFileHeaderRecord> centralRecords = new ArrayList<>(); List<ZipCentralDirectoryFileHeaderRecord> centralRecords = new ArrayList<>();
List<Long> centralRecordPositions = new ArrayList<>(); List<Long> centralRecordPositions = new ArrayList<>();