From 1f7affabd77b55ee2a107a788b189956e143afe9 Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 22 Apr 2022 16:37:17 -0700 Subject: [PATCH] Automatic code cleanup. PiperOrigin-RevId: 443787146 --- .../build/android/ziputils/Splitter.java | 59 ++++++----- .../build/android/ziputils/ZipIn.java | 97 ++++++++++--------- .../build/android/ziputils/ZipOut.java | 2 +- 3 files changed, 79 insertions(+), 79 deletions(-) diff --git a/src/tools/android/java/com/google/devtools/build/android/ziputils/Splitter.java b/src/tools/android/java/com/google/devtools/build/android/ziputils/Splitter.java index f363218ee28e65..7f1a469f10368d 100644 --- a/src/tools/android/java/com/google/devtools/build/android/ziputils/Splitter.java +++ b/src/tools/android/java/com/google/devtools/build/android/ziputils/Splitter.java @@ -47,10 +47,9 @@ public Splitter(int numberOfShards, int expectedSize) { } /** - * Forces mapping of the given entries to be that of the current shard. - * The estimated number of remaining entries to process is adjusted, - * by subtracting the number of as-of-yet unassigned entries from the - * filter. + * Forces mapping of the given entries to be that of the current shard. The estimated number of + * remaining entries to process is adjusted, by subtracting the number of as-of-yet unassigned + * entries from the filter. */ public void assign(Collection filter) { if (filter != null) { @@ -64,33 +63,7 @@ public void assign(Collection filter) { } } - /** - * Forces increment of the current shard. May be called externally. - * Typically right after calling {@link #assign(java.util.Collection)}. - */ - public void nextShard() { - if (shard < numberOfShards - 1) { - shard++; - size = 0; - addEntries(0); - } - } - - /** - * Adjusts the number of estimated entries to be process by the given count. - */ - public void addEntries(int count) { - this.remaining += count; - idealSize = numberOfShards > shard ? remaining / (numberOfShards - shard) : remaining; - // Before you change this, please do the math. - // It's not always perfect, but designed to keep shards reasonably balanced in most cases. - int limit = Math.min(Math.min(10, (idealSize + 3) / 4), (int) Math.log(numberOfShards)); - almostFull = idealSize - limit; - } - - /** - * Assigns the given entry to an output file. - */ + /** Assigns the given entry to an output file. */ public int assign(String path) { Preconditions.checkState(shard < numberOfShards, "Too many shards!"); Integer assignment = assigned.get(path); @@ -135,4 +108,28 @@ public int assign(String path) { size++; return shard; } + + /** + * Forces increment of the current shard. May be called externally. + * Typically right after calling {@link #assign(java.util.Collection)}. + */ + public void nextShard() { + if (shard < numberOfShards - 1) { + shard++; + size = 0; + addEntries(0); + } + } + + /** + * Adjusts the number of estimated entries to be process by the given count. + */ + public void addEntries(int count) { + this.remaining += count; + idealSize = numberOfShards > shard ? remaining / (numberOfShards - shard) : remaining; + // Before you change this, please do the math. + // It's not always perfect, but designed to keep shards reasonably balanced in most cases. + int limit = Math.min(Math.min(10, (idealSize + 3) / 4), (int) Math.log(numberOfShards)); + almostFull = idealSize - limit; + } } diff --git a/src/tools/android/java/com/google/devtools/build/android/ziputils/ZipIn.java b/src/tools/android/java/com/google/devtools/build/android/ziputils/ZipIn.java index 95683876aa3f83..83b5e625eaa02b 100644 --- a/src/tools/android/java/com/google/devtools/build/android/ziputils/ZipIn.java +++ b/src/tools/android/java/com/google/devtools/build/android/ziputils/ZipIn.java @@ -283,12 +283,11 @@ public ZipEntry entryAt(long offset) throws IOException { /** * Constructs a {@link ZipEntry} view of the entry at the location of the given header. * - * @param header a previously located header. If (@code useDirectory} is set, this will - * attempt to lookup a corresponding directory entry. If there is none, and {@code ignoreDeleted} - * is also set, the return value will flag this entry with a - * {@code ZipEntry.Status.ENTRY_NOT_FOUND} status code. - * - * @return {@link ZipEntry} for the given location. + * @param header a previously located header. If (@code useDirectory} is set, this will attempt to + * lookup a corresponding directory entry. If there is none, and {@code ignoreDeleted} is also + * set, the return value will flag this entry with a {@code ZipEntry.Status.ENTRY_NOT_FOUND} + * status code. + * @return {@link ZipEntry} for the given location. * @throws IOException */ public ZipEntry entryWith(LocalFileHeader header) throws IOException { @@ -307,43 +306,6 @@ public ZipEntry entryWith(LocalFileHeader header) throws IOException { return entryWith(header, dirEntry); } - /** - * Scans for a data descriptor from a given offset. - * - * @param offset position where to start the search. - * @param dirEntry directory entry for validation, or {@code null}. - * @return A data descriptor view for the next position containing the data descriptor signature. - * @throws IOException - */ - public DataDescriptor descriptorFrom(final long offset, final DirectoryEntry dirEntry) - throws IOException { - int skipped = 0; - for (ByteBuffer buffer = getData(offset + skipped, MAX_HEADER_SIZE); - buffer.limit() >= 16; buffer = getData(offset + skipped, MAX_HEADER_SIZE)) { - int markerOffset = ScanUtil.scanTo(DATA_DESC_SIG, buffer); - if (markerOffset < 0) { - skipped += buffer.limit() - 3; - } else { - skipped += markerOffset; - return markerOffset == 0 ? descriptorIn(buffer, offset + skipped, dirEntry) - : descriptorAt(offset + skipped, dirEntry); - } - } - return null; - } - - /** - * Creates a data descriptor view at a given offset. - * - * @param offset presumed location of data descriptor. - * @param dirEntry directory entry to use for validation, or {@code null}. - * @return a data descriptor view over the given file offset. - * @throws IOException - */ - public DataDescriptor descriptorAt(long offset, DirectoryEntry dirEntry) throws IOException { - return descriptorIn(getData(offset, 16), offset, dirEntry); - } - /** * Constructs a zip entry object for the location of the given header, with the corresponding * directory entry. @@ -379,8 +341,10 @@ private ZipEntry entryWith(LocalFileHeader header, DirectoryEntry dirEntry) thro content = getData(offset, sizeByDir); DataDescriptor dataDesc = descriptorAt(offset + sizeByDir, dirEntry); if (dataDesc != null) { - return zipEntry.withContent(content).withDescriptor(dataDesc).withCode( - ZipEntry.Status.ENTRY_OK); + return zipEntry + .withContent(content) + .withDescriptor(dataDesc) + .withCode(ZipEntry.Status.ENTRY_OK); } return zipEntry.withContent(content).withCode(ZipEntry.Status.NO_DATA_DESC); } @@ -404,13 +368,52 @@ private ZipEntry entryWith(LocalFileHeader header, DirectoryEntry dirEntry) thro return zipEntry.withDescriptor(dataDesc).withCode(ZipEntry.Status.UNKNOWN_SIZE); } content = getData(offset, sizeByDesc); - return zipEntry.withContent(content).withDescriptor(dataDesc).withCode( - ZipEntry.Status.ENTRY_OK); + return zipEntry + .withContent(content) + .withDescriptor(dataDesc) + .withCode(ZipEntry.Status.ENTRY_OK); } } return zipEntry.withCode(ZipEntry.Status.UNKNOWN_SIZE); } + /** + * Scans for a data descriptor from a given offset. + * + * @param offset position where to start the search. + * @param dirEntry directory entry for validation, or {@code null}. + * @return A data descriptor view for the next position containing the data descriptor signature. + * @throws IOException + */ + public DataDescriptor descriptorFrom(final long offset, final DirectoryEntry dirEntry) + throws IOException { + int skipped = 0; + for (ByteBuffer buffer = getData(offset + skipped, MAX_HEADER_SIZE); + buffer.limit() >= 16; buffer = getData(offset + skipped, MAX_HEADER_SIZE)) { + int markerOffset = ScanUtil.scanTo(DATA_DESC_SIG, buffer); + if (markerOffset < 0) { + skipped += buffer.limit() - 3; + } else { + skipped += markerOffset; + return markerOffset == 0 ? descriptorIn(buffer, offset + skipped, dirEntry) + : descriptorAt(offset + skipped, dirEntry); + } + } + return null; + } + + /** + * Creates a data descriptor view at a given offset. + * + * @param offset presumed location of data descriptor. + * @param dirEntry directory entry to use for validation, or {@code null}. + * @return a data descriptor view over the given file offset. + * @throws IOException + */ + public DataDescriptor descriptorAt(long offset, DirectoryEntry dirEntry) throws IOException { + return descriptorIn(getData(offset, 16), offset, dirEntry); + } + /** * Constructs a local header view over a give byte buffer. * diff --git a/src/tools/android/java/com/google/devtools/build/android/ziputils/ZipOut.java b/src/tools/android/java/com/google/devtools/build/android/ziputils/ZipOut.java index 104ebb0bba7162..bbc1ea7d74de59 100644 --- a/src/tools/android/java/com/google/devtools/build/android/ziputils/ZipOut.java +++ b/src/tools/android/java/com/google/devtools/build/android/ziputils/ZipOut.java @@ -214,7 +214,7 @@ public void run() { try { fileChannel.write(buffer); } catch (IOException ex) { - throw new IllegalStateException("Unexpected IOException writing to output channel"); + throw new IllegalStateException("Unexpected IOException writing to output channel", ex); } } }