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:
@@ -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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.boot.loader.zip;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.ClosedByInterruptException;
|
||||
@@ -29,14 +30,14 @@ import java.util.function.Supplier;
|
||||
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.
|
||||
*
|
||||
* @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;
|
||||
|
||||
@@ -46,13 +47,13 @@ class FileChannelDataBlock implements CloseableDataBlock {
|
||||
|
||||
private final long size;
|
||||
|
||||
FileChannelDataBlock(Path path) throws IOException {
|
||||
FileDataBlock(Path path) throws IOException {
|
||||
this.channel = new ManagedFileChannel(path);
|
||||
this.offset = 0;
|
||||
this.size = Files.size(path);
|
||||
}
|
||||
|
||||
FileChannelDataBlock(ManagedFileChannel channel, long offset, long size) {
|
||||
FileDataBlock(ManagedFileChannel channel, long offset, long size) {
|
||||
this.channel = channel;
|
||||
this.offset = offset;
|
||||
this.size = size;
|
||||
@@ -115,26 +116,26 @@ class FileChannelDataBlock implements CloseableDataBlock {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a new {@link FileChannelDataBlock} slice providing access to a subset of the
|
||||
* data. The caller is responsible for calling {@link #open()} and {@link #close()} on
|
||||
* the returned block.
|
||||
* Return a new {@link FileDataBlock} slice providing access to a subset of the data.
|
||||
* The caller is responsible for calling {@link #open()} and {@link #close()} on the
|
||||
* returned 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
|
||||
*/
|
||||
FileChannelDataBlock slice(long offset) throws IOException {
|
||||
FileDataBlock slice(long offset) throws IOException {
|
||||
return slice(offset, this.size - offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a new {@link FileChannelDataBlock} slice providing access to a subset of the
|
||||
* data. The caller is responsible for calling {@link #open()} and {@link #close()} on
|
||||
* the returned block.
|
||||
* Return a new {@link FileDataBlock} slice providing access to a subset of the data.
|
||||
* The caller is responsible for calling {@link #open()} and {@link #close()} on the
|
||||
* returned block.
|
||||
* @param offset the start offset for the slice relative to this block
|
||||
* @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) {
|
||||
return this;
|
||||
}
|
||||
@@ -145,7 +146,7 @@ class FileChannelDataBlock implements CloseableDataBlock {
|
||||
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);
|
||||
return new FileChannelDataBlock(this.channel, this.offset + offset, size);
|
||||
return new FileDataBlock(this.channel, this.offset + offset, size);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,7 +74,7 @@ public final class ZipContent implements Closeable {
|
||||
|
||||
private final Kind kind;
|
||||
|
||||
private final FileChannelDataBlock data;
|
||||
private final FileDataBlock data;
|
||||
|
||||
private final long centralDirectoryPos;
|
||||
|
||||
@@ -96,7 +96,7 @@ public final class ZipContent implements Closeable {
|
||||
|
||||
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,
|
||||
NameOffsetLookups nameOffsetLookups, boolean hasJarSignatureFile) {
|
||||
this.source = source;
|
||||
@@ -449,7 +449,7 @@ public final class ZipContent implements Closeable {
|
||||
|
||||
private final Source source;
|
||||
|
||||
private final FileChannelDataBlock data;
|
||||
private final FileDataBlock data;
|
||||
|
||||
private final long centralDirectoryPos;
|
||||
|
||||
@@ -463,8 +463,7 @@ public final class ZipContent implements Closeable {
|
||||
|
||||
private int cursor;
|
||||
|
||||
private Loader(Source source, Entry directoryEntry, FileChannelDataBlock data, long centralDirectoryPos,
|
||||
int maxSize) {
|
||||
private Loader(Source source, Entry directoryEntry, FileDataBlock data, long centralDirectoryPos, int maxSize) {
|
||||
this.source = source;
|
||||
this.data = data;
|
||||
this.centralDirectoryPos = centralDirectoryPos;
|
||||
@@ -561,7 +560,7 @@ public final class ZipContent implements Closeable {
|
||||
|
||||
private static ZipContent loadNonNested(Source source) throws IOException {
|
||||
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 {
|
||||
@@ -573,7 +572,7 @@ public final class ZipContent implements Closeable {
|
||||
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 {
|
||||
data.open();
|
||||
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 eocd = locatedEocd.endOfCentralDirectoryRecord();
|
||||
long eocdPos = locatedEocd.pos();
|
||||
@@ -634,7 +633,7 @@ public final class ZipContent implements Closeable {
|
||||
* @return the offset within the data where the archive begins
|
||||
* @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 {
|
||||
long specifiedOffsetToStartOfCentralDirectory = (zip64Eocd != null)
|
||||
? zip64Eocd.offsetToStartOfCentralDirectory() : eocd.offsetToStartOfCentralDirectory();
|
||||
@@ -699,7 +698,7 @@ public final class ZipContent implements Closeable {
|
||||
|
||||
private volatile String name;
|
||||
|
||||
private volatile FileChannelDataBlock content;
|
||||
private volatile FileDataBlock content;
|
||||
|
||||
/**
|
||||
* Create a new {@link Entry} instance.
|
||||
@@ -789,13 +788,13 @@ public final class ZipContent implements Closeable {
|
||||
* @throws IOException on I/O error
|
||||
*/
|
||||
public CloseableDataBlock openContent() throws IOException {
|
||||
FileChannelDataBlock content = getContent();
|
||||
FileDataBlock content = getContent();
|
||||
content.open();
|
||||
return content;
|
||||
}
|
||||
|
||||
private FileChannelDataBlock getContent() throws IOException {
|
||||
FileChannelDataBlock content = this.content;
|
||||
private FileDataBlock getContent() throws IOException {
|
||||
FileDataBlock content = this.content;
|
||||
if (content == null) {
|
||||
int pos = this.centralRecord.offsetToLocalHeader();
|
||||
checkNotZip64Extended(pos);
|
||||
|
||||
Reference in New Issue
Block a user