Skip to content

Commit 4203e1f

Browse files
committed
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
1 parent 778c528 commit 4203e1f

File tree

7 files changed

+67
-66
lines changed

7 files changed

+67
-66
lines changed
Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.boot.loader.zip;
1818

19+
import java.io.File;
1920
import java.io.IOException;
2021
import java.nio.ByteBuffer;
2122
import java.nio.channels.ClosedByInterruptException;
@@ -29,14 +30,14 @@
2930
import org.springframework.boot.loader.log.DebugLogger;
3031

3132
/**
32-
* Reference counted {@link DataBlock} implementation backed by a {@link FileChannel} with
33+
* Reference counted {@link DataBlock} implementation backed by a {@link File} with
3334
* support for slicing.
3435
*
3536
* @author Phillip Webb
3637
*/
37-
class FileChannelDataBlock implements CloseableDataBlock {
38+
class FileDataBlock implements CloseableDataBlock {
3839

39-
private static final DebugLogger debug = DebugLogger.get(FileChannelDataBlock.class);
40+
private static final DebugLogger debug = DebugLogger.get(FileDataBlock.class);
4041

4142
static Tracker tracker;
4243

@@ -46,13 +47,13 @@ class FileChannelDataBlock implements CloseableDataBlock {
4647

4748
private final long size;
4849

49-
FileChannelDataBlock(Path path) throws IOException {
50+
FileDataBlock(Path path) throws IOException {
5051
this.channel = new ManagedFileChannel(path);
5152
this.offset = 0;
5253
this.size = Files.size(path);
5354
}
5455

55-
FileChannelDataBlock(ManagedFileChannel channel, long offset, long size) {
56+
FileDataBlock(ManagedFileChannel channel, long offset, long size) {
5657
this.channel = channel;
5758
this.offset = offset;
5859
this.size = size;
@@ -115,26 +116,26 @@ <E extends Exception> void ensureOpen(Supplier<E> exceptionSupplier) throws E {
115116
}
116117

117118
/**
118-
* Return a new {@link FileChannelDataBlock} slice providing access to a subset of the
119-
* data. The caller is responsible for calling {@link #open()} and {@link #close()} on
120-
* the returned block.
119+
* Return a new {@link FileDataBlock} slice providing access to a subset of the data.
120+
* The caller is responsible for calling {@link #open()} and {@link #close()} on the
121+
* returned block.
121122
* @param offset the start offset for the slice relative to this block
122-
* @return a new {@link FileChannelDataBlock} instance
123+
* @return a new {@link FileDataBlock} instance
123124
* @throws IOException on I/O error
124125
*/
125-
FileChannelDataBlock slice(long offset) throws IOException {
126+
FileDataBlock slice(long offset) throws IOException {
126127
return slice(offset, this.size - offset);
127128
}
128129

129130
/**
130-
* Return a new {@link FileChannelDataBlock} slice providing access to a subset of the
131-
* data. The caller is responsible for calling {@link #open()} and {@link #close()} on
132-
* the returned block.
131+
* Return a new {@link FileDataBlock} slice providing access to a subset of the data.
132+
* The caller is responsible for calling {@link #open()} and {@link #close()} on the
133+
* returned block.
133134
* @param offset the start offset for the slice relative to this block
134135
* @param size the size of the new slice
135-
* @return a new {@link FileChannelDataBlock} instance
136+
* @return a new {@link FileDataBlock} instance
136137
*/
137-
FileChannelDataBlock slice(long offset, long size) {
138+
FileDataBlock slice(long offset, long size) {
138139
if (offset == 0 && size == this.size) {
139140
return this;
140141
}
@@ -145,7 +146,7 @@ FileChannelDataBlock slice(long offset, long size) {
145146
throw new IllegalArgumentException("Size must not be negative and must be within bounds");
146147
}
147148
debug.log("Slicing %s at %s with size %s", this.channel, offset, size);
148-
return new FileChannelDataBlock(this.channel, this.offset + offset, size);
149+
return new FileDataBlock(this.channel, this.offset + offset, size);
149150
}
150151

151152
/**

spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/zip/ZipContent.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public final class ZipContent implements Closeable {
7474

7575
private final Kind kind;
7676

77-
private final FileChannelDataBlock data;
77+
private final FileDataBlock data;
7878

7979
private final long centralDirectoryPos;
8080

@@ -96,7 +96,7 @@ public final class ZipContent implements Closeable {
9696

9797
private SoftReference<Map<Class<?>, Object>> info;
9898

99-
private ZipContent(Source source, Kind kind, FileChannelDataBlock data, long centralDirectoryPos, long commentPos,
99+
private ZipContent(Source source, Kind kind, FileDataBlock data, long centralDirectoryPos, long commentPos,
100100
long commentLength, int[] lookupIndexes, int[] nameHashLookups, int[] relativeCentralDirectoryOffsetLookups,
101101
NameOffsetLookups nameOffsetLookups, boolean hasJarSignatureFile) {
102102
this.source = source;
@@ -449,7 +449,7 @@ private static final class Loader {
449449

450450
private final Source source;
451451

452-
private final FileChannelDataBlock data;
452+
private final FileDataBlock data;
453453

454454
private final long centralDirectoryPos;
455455

@@ -463,8 +463,7 @@ private static final class Loader {
463463

464464
private int cursor;
465465

466-
private Loader(Source source, Entry directoryEntry, FileChannelDataBlock data, long centralDirectoryPos,
467-
int maxSize) {
466+
private Loader(Source source, Entry directoryEntry, FileDataBlock data, long centralDirectoryPos, int maxSize) {
468467
this.source = source;
469468
this.data = data;
470469
this.centralDirectoryPos = centralDirectoryPos;
@@ -561,7 +560,7 @@ static ZipContent load(Source source) throws IOException {
561560

562561
private static ZipContent loadNonNested(Source source) throws IOException {
563562
debug.log("Loading non-nested zip '%s'", source.path());
564-
return openAndLoad(source, Kind.ZIP, new FileChannelDataBlock(source.path()));
563+
return openAndLoad(source, Kind.ZIP, new FileDataBlock(source.path()));
565564
}
566565

567566
private static ZipContent loadNestedZip(Source source, Entry entry) throws IOException {
@@ -573,7 +572,7 @@ private static ZipContent loadNestedZip(Source source, Entry entry) throws IOExc
573572
return openAndLoad(source, Kind.NESTED_ZIP, entry.getContent());
574573
}
575574

576-
private static ZipContent openAndLoad(Source source, Kind kind, FileChannelDataBlock data) throws IOException {
575+
private static ZipContent openAndLoad(Source source, Kind kind, FileDataBlock data) throws IOException {
577576
try {
578577
data.open();
579578
return loadContent(source, kind, data);
@@ -584,7 +583,7 @@ private static ZipContent openAndLoad(Source source, Kind kind, FileChannelDataB
584583
}
585584
}
586585

587-
private static ZipContent loadContent(Source source, Kind kind, FileChannelDataBlock data) throws IOException {
586+
private static ZipContent loadContent(Source source, Kind kind, FileDataBlock data) throws IOException {
588587
ZipEndOfCentralDirectoryRecord.Located locatedEocd = ZipEndOfCentralDirectoryRecord.load(data);
589588
ZipEndOfCentralDirectoryRecord eocd = locatedEocd.endOfCentralDirectoryRecord();
590589
long eocdPos = locatedEocd.pos();
@@ -634,7 +633,7 @@ private static ZipContent loadContent(Source source, Kind kind, FileChannelDataB
634633
* @return the offset within the data where the archive begins
635634
* @throws IOException on I/O error
636635
*/
637-
private static long getStartOfZipContent(FileChannelDataBlock data, ZipEndOfCentralDirectoryRecord eocd,
636+
private static long getStartOfZipContent(FileDataBlock data, ZipEndOfCentralDirectoryRecord eocd,
638637
Zip64EndOfCentralDirectoryRecord zip64Eocd) throws IOException {
639638
long specifiedOffsetToStartOfCentralDirectory = (zip64Eocd != null)
640639
? zip64Eocd.offsetToStartOfCentralDirectory() : eocd.offsetToStartOfCentralDirectory();
@@ -699,7 +698,7 @@ public class Entry {
699698

700699
private volatile String name;
701700

702-
private volatile FileChannelDataBlock content;
701+
private volatile FileDataBlock content;
703702

704703
/**
705704
* Create a new {@link Entry} instance.
@@ -789,13 +788,13 @@ public int getUncompressedSize() {
789788
* @throws IOException on I/O error
790789
*/
791790
public CloseableDataBlock openContent() throws IOException {
792-
FileChannelDataBlock content = getContent();
791+
FileDataBlock content = getContent();
793792
content.open();
794793
return content;
795794
}
796795

797-
private FileChannelDataBlock getContent() throws IOException {
798-
FileChannelDataBlock content = this.content;
796+
private FileDataBlock getContent() throws IOException {
797+
FileDataBlock content = this.content;
799798
if (content == null) {
800799
int pos = this.centralRecord.offsetToLocalHeader();
801800
checkNotZip64Extended(pos);

spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/zip/AssertFileChannelDataBlocksClosed.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,8 +25,8 @@
2525
import org.junit.jupiter.api.extension.ExtendWith;
2626

2727
/**
28-
* Annotation that can be added to tests to assert that {@link FileChannelDataBlock} files
29-
* are not left open.
28+
* Annotation that can be added to tests to assert that {@link FileDataBlock} files are
29+
* not left open.
3030
*
3131
* @author Phillip Webb
3232
*/

spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/zip/AssertFileChannelDataBlocksClosedExtension.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import org.junit.jupiter.api.extension.ExtensionContext;
3232

3333
import org.springframework.boot.loader.ref.DefaultCleanerTracking;
34-
import org.springframework.boot.loader.zip.FileChannelDataBlock.Tracker;
34+
import org.springframework.boot.loader.zip.FileDataBlock.Tracker;
3535

3636
import static org.assertj.core.api.Assertions.assertThat;
3737

@@ -45,14 +45,14 @@ class AssertFileChannelDataBlocksClosedExtension implements BeforeEachCallback,
4545
@Override
4646
public void beforeEach(ExtensionContext context) throws Exception {
4747
tracker.clear();
48-
FileChannelDataBlock.tracker = tracker;
48+
FileDataBlock.tracker = tracker;
4949
DefaultCleanerTracking.set(tracker::addedCleanable);
5050
}
5151

5252
@Override
5353
public void afterEach(ExtensionContext context) throws Exception {
5454
tracker.assertAllClosed();
55-
FileChannelDataBlock.tracker = null;
55+
FileDataBlock.tracker = null;
5656
}
5757

5858
private static final class OpenFilesTracker implements Tracker {

spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/zip/FileChannelDataBlockManagedFileChannel.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.boot.loader.zip;
1818

19-
import org.springframework.boot.loader.zip.FileChannelDataBlock.ManagedFileChannel;
19+
import org.springframework.boot.loader.zip.FileDataBlock.ManagedFileChannel;
2020

2121
/**
2222
* Test access to {@link ManagedFileChannel} details.
@@ -28,6 +28,6 @@ public final class FileChannelDataBlockManagedFileChannel {
2828
private FileChannelDataBlockManagedFileChannel() {
2929
}
3030

31-
public static int BUFFER_SIZE = FileChannelDataBlock.ManagedFileChannel.BUFFER_SIZE;
31+
public static int BUFFER_SIZE = FileDataBlock.ManagedFileChannel.BUFFER_SIZE;
3232

3333
}

0 commit comments

Comments
 (0)