mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Polish
This commit is contained in:
parent
0a4d58f221
commit
cfeafee826
@ -106,11 +106,15 @@ public class WebMvcMetricsFilter extends OncePerRequestFilter {
|
||||
}
|
||||
catch (Exception ex) {
|
||||
response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
|
||||
record(timingContext, request, response, (ex instanceof NestedServletException) ? ex.getCause() : ex);
|
||||
record(timingContext, request, response, unwrapNestedServletException(ex));
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
private Throwable unwrapNestedServletException(Throwable ex) {
|
||||
return (ex instanceof NestedServletException) ? ex.getCause() : ex;
|
||||
}
|
||||
|
||||
private TimingContext startAndAttachTimingContext(HttpServletRequest request) {
|
||||
Timer.Sample timerSample = Timer.start(this.registry);
|
||||
TimingContext timingContext = new TimingContext(timerSample);
|
||||
|
@ -34,9 +34,9 @@ import org.springframework.boot.loader.data.RandomAccessData;
|
||||
|
||||
/**
|
||||
* Provides access to entries from a {@link JarFile}. In order to reduce memory
|
||||
* consumption entry details are stored using int arrays. The {@code hashCodes} array
|
||||
* stores the hash code of the entry name, the {@code centralDirectoryOffsets} provides
|
||||
* the offset to the central directory record and {@code positions} provides the original
|
||||
* consumption entry details are stored using arrays. The {@code hashCodes} array stores
|
||||
* the hash code of the entry name, the {@code centralDirectoryOffsets} provides the
|
||||
* offset to the central directory record and {@code positions} provides the original
|
||||
* order position of the entry. The arrays are stored in hashCode order so that a binary
|
||||
* search can be used to find a name.
|
||||
* <p>
|
||||
@ -120,7 +120,7 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable<JarEntry> {
|
||||
int maxSize = endRecord.getNumberOfRecords();
|
||||
this.centralDirectoryData = centralDirectoryData;
|
||||
this.hashCodes = new int[maxSize];
|
||||
this.centralDirectoryOffsets = Offsets.of(endRecord);
|
||||
this.centralDirectoryOffsets = Offsets.get(endRecord);
|
||||
this.positions = new int[maxSize];
|
||||
}
|
||||
|
||||
@ -187,12 +187,6 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable<JarEntry> {
|
||||
swap(this.positions, i, j);
|
||||
}
|
||||
|
||||
private static void swap(int[] array, int i, int j) {
|
||||
int temp = array[i];
|
||||
array[i] = array[j];
|
||||
array[j] = temp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<JarEntry> iterator() {
|
||||
return new EntryIterator(NO_VALIDATION);
|
||||
@ -388,6 +382,18 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable<JarEntry> {
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static void swap(int[] array, int i, int j) {
|
||||
int temp = array[i];
|
||||
array[i] = array[j];
|
||||
array[j] = temp;
|
||||
}
|
||||
|
||||
private static void swap(long[] array, int i, int j) {
|
||||
long temp = array[i];
|
||||
array[i] = array[j];
|
||||
array[j] = temp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterator for contained entries.
|
||||
*/
|
||||
@ -421,6 +427,11 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable<JarEntry> {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface to manage offsets to central directory records. Regular zip files are
|
||||
* backed by an {@code int[]} based implementation, Zip64 files are backed by a
|
||||
* {@code long[]} and will consume more memory.
|
||||
*/
|
||||
private interface Offsets {
|
||||
|
||||
void set(int index, long value);
|
||||
@ -429,13 +440,16 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable<JarEntry> {
|
||||
|
||||
void swap(int i, int j);
|
||||
|
||||
static Offsets of(CentralDirectoryEndRecord endRecord) {
|
||||
return endRecord.isZip64() ? new Zip64Offsets(endRecord.getNumberOfRecords())
|
||||
: new ZipOffsets(endRecord.getNumberOfRecords());
|
||||
static Offsets get(CentralDirectoryEndRecord endRecord) {
|
||||
int size = endRecord.getNumberOfRecords();
|
||||
return endRecord.isZip64() ? new Zip64Offsets(size) : new ZipOffsets(size);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Offsets} implementation for regular zip files.
|
||||
*/
|
||||
private static final class ZipOffsets implements Offsets {
|
||||
|
||||
private final int[] offsets;
|
||||
@ -461,6 +475,9 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable<JarEntry> {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Offsets} implementation for zip64 files.
|
||||
*/
|
||||
private static final class Zip64Offsets implements Offsets {
|
||||
|
||||
private final long[] offsets;
|
||||
@ -471,9 +488,7 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable<JarEntry> {
|
||||
|
||||
@Override
|
||||
public void swap(int i, int j) {
|
||||
long temp = this.offsets[i];
|
||||
this.offsets[i] = this.offsets[j];
|
||||
this.offsets[j] = temp;
|
||||
JarFileEntries.swap(this.offsets, i, j);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user