Skip to content

Commit 226e0e3

Browse files
authored
Merge pull request #138 from solrudev/develop
0.15.2
2 parents 2ba113e + 7ebb1b8 commit 226e0e3

57 files changed

Lines changed: 1722 additions & 493 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Ackpine depends on Jetpack libraries, so it's also necessary to add the `google(
3535

3636
```toml
3737
[versions]
38-
ackpine = "0.15.1"
38+
ackpine = "0.15.2"
3939

4040
[libraries]
4141
ackpine-core = { module = "ru.solrudev.ackpine:ackpine-core", version.ref = "ackpine" }
@@ -76,7 +76,7 @@ ackpine = [
7676

7777
```kotlin
7878
dependencies {
79-
val ackpineVersion = "0.15.1"
79+
val ackpineVersion = "0.15.2"
8080
implementation("ru.solrudev.ackpine:ackpine-core:$ackpineVersion")
8181

8282
// optional - Kotlin extensions and Coroutines support

ackpine-api/api-main/src/main/kotlin/ru/solrudev/ackpine/SdkIntWrapper.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
package ru.solrudev.ackpine
1818

19+
import androidx.annotation.RestrictTo
20+
21+
@RestrictTo(RestrictTo.Scope.LIBRARY)
1922
internal object SdkIntWrapper {
2023
@JvmSynthetic
2124
fun get() = try {

ackpine-splits/compress-android/build.gradle.kts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ import ru.solrudev.ackpine.gradle.versioning.ackpineVersion
1818

1919
description = "Fork of Apache Commons Compress, compatible with Android API 19+. " +
2020
"Contains only a subset of Compress API."
21-
version = "1.27.1-${ackpineVersion.get()}"
21+
version = "1.28.0-${ackpineVersion.get()}"
2222

2323
plugins {
2424
id("ru.solrudev.ackpine.library.base")
2525
id("ru.solrudev.ackpine.library-publish")
26+
id("ru.solrudev.ackpine.optional-dependencies")
2627
}
2728

2829
ackpine {
@@ -142,4 +143,6 @@ mavenPublishing {
142143
dependencies {
143144
implementation(androidx.core)
144145
implementation(libs.apache.commons.io)
146+
optional(libs.zstd)
147+
optional(libs.xz)
145148
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package ru.solrudev.ackpine.compress;
20+
21+
import java.io.IOException;
22+
23+
/**
24+
* Signals that a Pack200 Compress exception of some sort has occurred.
25+
*
26+
* @since 1.28.0
27+
*/
28+
public class CompressException extends IOException {
29+
30+
/** Serial. */
31+
private static final long serialVersionUID = 1;
32+
33+
/**
34+
* Constructs an {@code CompressException} with {@code null} as its error detail message.
35+
*/
36+
public CompressException() {
37+
// empty
38+
}
39+
40+
/**
41+
* Constructs a new exception with the specified detail message. The cause is not initialized.
42+
*
43+
* @param message The message (which is saved for later retrieval by the {@link #getMessage()} method).
44+
*/
45+
public CompressException(final String message) {
46+
super(message);
47+
}
48+
49+
/**
50+
* Constructs a new exception with the specified detail message and cause.
51+
*
52+
* @param message The message (which is saved for later retrieval by the {@link #getMessage()} method).
53+
* @param cause The cause (which is saved for later retrieval by the {@link #getCause()} method). A null value indicates that the cause is nonexistent or
54+
* unknown.
55+
*/
56+
public CompressException(final String message, final Throwable cause) {
57+
super(message, cause);
58+
}
59+
60+
/**
61+
* Constructs a {@code CompressException} with the specified cause and a detail message.
62+
*
63+
* @param cause The cause (which is saved for later retrieval by the {@link #getCause()} method). (A null value is permitted, and indicates that the cause
64+
* is nonexistent or unknown.)
65+
*/
66+
public CompressException(final Throwable cause) {
67+
super(cause);
68+
}
69+
}

ackpine-splits/compress-android/src/main/java/ru/solrudev/ackpine/compress/MemoryLimitException.java

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,45 +18,82 @@
1818
*/
1919
package ru.solrudev.ackpine.compress;
2020

21-
import java.io.IOException;
22-
2321
/**
2422
* If a stream checks for estimated memory allocation, and the estimate goes above the memory limit, this is thrown. This can also be thrown if a stream tries
2523
* to allocate a byte array that is larger than the allowable limit.
2624
*
2725
* @since 1.14
2826
*/
29-
public class MemoryLimitException extends IOException {
27+
public class MemoryLimitException extends CompressException {
3028

3129
private static final long serialVersionUID = 1L;
3230

3331
private static String buildMessage(final long memoryNeededInKb, final int memoryLimitInKb) {
34-
return memoryNeededInKb + " kb of memory would be needed; limit was " + memoryLimitInKb + " kb. "
35-
+ "If the file is not corrupt, consider increasing the memory limit.";
32+
return String.format("%,d KiB of memory would be needed; limit was %,d KiB. If the file is not corrupt, consider increasing the memory limit.",
33+
memoryNeededInKb, memoryLimitInKb);
3634
}
3735

3836
/** A long instead of int to account for overflow for corrupt files. */
39-
private final long memoryNeededInKb;
37+
private final long memoryNeededKiB;
38+
private final int memoryLimitKiB;
4039

41-
private final int memoryLimitInKb;
40+
/**
41+
* Constructs a new instance.
42+
*
43+
* @param memoryNeededKiB The memory needed in kibibytes (KiB).
44+
* @param memoryLimitKiB The memory limit in kibibytes (KiB).
45+
*/
46+
public MemoryLimitException(final long memoryNeededKiB, final int memoryLimitKiB) {
47+
super(buildMessage(memoryNeededKiB, memoryLimitKiB));
48+
this.memoryNeededKiB = memoryNeededKiB;
49+
this.memoryLimitKiB = memoryLimitKiB;
50+
}
4251

43-
public MemoryLimitException(final long memoryNeededInKb, final int memoryLimitInKb) {
44-
super(buildMessage(memoryNeededInKb, memoryLimitInKb));
45-
this.memoryNeededInKb = memoryNeededInKb;
46-
this.memoryLimitInKb = memoryLimitInKb;
52+
/**
53+
* Constructs a new instance.
54+
*
55+
* @param memoryNeededKiB The memory needed in kibibytes (KiB).
56+
* @param memoryLimitKiB The memory limit in kibibytes (KiB).
57+
* @param cause The cause (which is saved for later retrieval by the {@link #getCause()} method). (A null value is permitted, and indicates that
58+
* the cause is nonexistent or unknown.)
59+
* @deprecated Use {@link #MemoryLimitException(long, int, Throwable)}.
60+
*/
61+
@Deprecated
62+
public MemoryLimitException(final long memoryNeededKiB, final int memoryLimitKiB, final Exception cause) {
63+
super(buildMessage(memoryNeededKiB, memoryLimitKiB), cause);
64+
this.memoryNeededKiB = memoryNeededKiB;
65+
this.memoryLimitKiB = memoryLimitKiB;
4766
}
4867

49-
public MemoryLimitException(final long memoryNeededInKb, final int memoryLimitInKb, final Exception e) {
50-
super(buildMessage(memoryNeededInKb, memoryLimitInKb), e);
51-
this.memoryNeededInKb = memoryNeededInKb;
52-
this.memoryLimitInKb = memoryLimitInKb;
68+
/**
69+
* Constructs a new instance.
70+
*
71+
* @param memoryNeededKiB The memory needed in kibibytes (KiB).
72+
* @param memoryLimitKiB The memory limit in kibibytes (KiB).
73+
* @param cause The cause (which is saved for later retrieval by the {@link #getCause()} method). (A null value is permitted, and indicates that
74+
* the cause is nonexistent or unknown.)
75+
*/
76+
public MemoryLimitException(final long memoryNeededKiB, final int memoryLimitKiB, final Throwable cause) {
77+
super(buildMessage(memoryNeededKiB, memoryLimitKiB), cause);
78+
this.memoryNeededKiB = memoryNeededKiB;
79+
this.memoryLimitKiB = memoryLimitKiB;
5380
}
5481

82+
/**
83+
* Gets the memory limit in kibibytes (KiB).
84+
*
85+
* @return the memory limit in kibibytes (KiB).
86+
*/
5587
public int getMemoryLimitInKb() {
56-
return memoryLimitInKb;
88+
return memoryLimitKiB;
5789
}
5890

91+
/**
92+
* Gets the memory needed in kibibytes (KiB).
93+
*
94+
* @return the memory needed in kibibytes (KiB).
95+
*/
5996
public long getMemoryNeededInKb() {
60-
return memoryNeededInKb;
97+
return memoryNeededKiB;
6198
}
6299
}

ackpine-splits/compress-android/src/main/java/ru/solrudev/ackpine/compress/archivers/ArchiveInputStream.java

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@
2727
import org.apache.commons.io.input.NullInputStream;
2828

2929
/**
30-
* Archive input streams <b>MUST</b> override the {@link #read(byte[], int, int)} - or {@link #read()} - method so that reading from the stream generates EOF
31-
* for the end of data in each entry as well as at the end of the file proper.
30+
* Archive input streams <strong>MUST</strong> override the {@link #read(byte[], int, int)} - or {@link #read()} - method so that reading from the stream
31+
* generates EOF for the end of data in each entry as well as at the end of the file proper.
3232
* <p>
3333
* The {@link #getNextEntry()} method is used to reset the input stream ready for reading the data from the next entry.
3434
* </p>
3535
* <p>
3636
* The input stream classes must also implement a method with the signature:
3737
* </p>
38+
*
3839
* <pre>
3940
* public static boolean matches(byte[] signature, int length)
4041
* </pre>
@@ -50,16 +51,17 @@ public abstract class ArchiveInputStream<E extends ArchiveEntry> extends FilterI
5051

5152
private final byte[] single = new byte[1];
5253

53-
/** The number of bytes read in this stream */
54+
/** The number of bytes read in this stream. */
5455
private long bytesRead;
5556

5657
private Charset charset;
5758

5859
/**
5960
* Constructs a new instance.
6061
*/
62+
@SuppressWarnings("resource")
6163
public ArchiveInputStream() {
62-
this(NullInputStream.INSTANCE, Charset.defaultCharset());
64+
this(new NullInputStream(), Charset.defaultCharset());
6365
}
6466

6567
/**
@@ -87,33 +89,32 @@ protected ArchiveInputStream(final InputStream inputStream, final String charset
8789
}
8890

8991
/**
90-
* Whether this stream is able to read the given entry.
92+
* Tests whether this stream is able to read the given entry.
9193
* <p>
9294
* Some archive formats support variants or details that are not supported (yet).
9395
* </p>
9496
*
95-
* @param archiveEntry the entry to test
97+
* @param archiveEntry the entry to test.
9698
* @return This implementation always returns true.
97-
*
9899
* @since 1.1
99100
*/
100101
public boolean canReadEntryData(final ArchiveEntry archiveEntry) {
101102
return true;
102103
}
103104

104105
/**
105-
* Increments the counter of already read bytes. Doesn't increment if the EOF has been hit (read == -1)
106+
* Increments the counter of already read bytes. Doesn't increment if the EOF has been hit (read == -1).
106107
*
107-
* @param read the number of bytes read
108+
* @param read the number of bytes read.
108109
*/
109110
protected void count(final int read) {
110111
count((long) read);
111112
}
112113

113114
/**
114-
* Increments the counter of already read bytes. Doesn't increment if the EOF has been hit (read == -1)
115+
* Increments the counter of already read bytes. Doesn't increment if the EOF has been hit (read == -1).
115116
*
116-
* @param read the number of bytes read
117+
* @param read the number of bytes read.
117118
* @since 1.1
118119
*/
119120
protected void count(final long read) {
@@ -133,9 +134,9 @@ public long getBytesRead() {
133134
}
134135

135136
/**
136-
* Gets the Charest.
137+
* Gets the Charset.
137138
*
138-
* @return the Charest.
139+
* @return the Charset.
139140
*/
140141
public Charset getCharset() {
141142
return charset;
@@ -144,7 +145,7 @@ public Charset getCharset() {
144145
/**
145146
* Gets the current number of bytes read from this stream.
146147
*
147-
* @return the number of read bytes
148+
* @return the number of read.
148149
* @deprecated this method may yield wrong results for large archives, use {@link #getBytesRead()} instead.
149150
*/
150151
@Deprecated
@@ -162,8 +163,9 @@ public int getCount() {
162163

163164
/**
164165
* Does nothing.
165-
*
166+
* <p>
166167
* TODO [COMPRESS-670] Support mark() and reset() in ArchiveInputStream.
168+
* </p>
167169
*
168170
* @param readlimit ignored.
169171
*/
@@ -174,8 +176,9 @@ public synchronized void mark(final int readlimit) {
174176

175177
/**
176178
* Always returns false.
177-
*
179+
* <p>
178180
* TODO [COMPRESS-670] Support mark() and reset() in ArchiveInputStream.
181+
* </p>
179182
*
180183
* @return Always returns false.
181184
*/
@@ -196,13 +199,15 @@ protected void pushedBackBytes(final long pushedBack) {
196199

197200
/**
198201
* Reads a byte of data. This method will block until enough input is available.
199-
*
202+
* <p>
200203
* Simply calls the {@link #read(byte[], int, int)} method.
201-
*
204+
* </p>
205+
* <p>
202206
* MUST be overridden if the {@link #read(byte[], int, int)} method is not overridden; may be overridden otherwise.
207+
* </p>
203208
*
204-
* @return the byte read, or -1 if end of input is reached
205-
* @throws IOException if an I/O error has occurred
209+
* @return the byte read, or -1 if end of input is reached.
210+
* @throws IOException if an I/O error has occurred.
206211
*/
207212
@Override
208213
public int read() throws IOException {
@@ -212,8 +217,9 @@ public int read() throws IOException {
212217

213218
/**
214219
* Does nothing.
215-
*
220+
* <p>
216221
* TODO [COMPRESS-670] Support mark() and reset() in ArchiveInputStream.
222+
* </p>
217223
*
218224
* @throws IOException not thrown here but may be thrown from a subclass.
219225
*/

ackpine-splits/compress-android/src/main/java/ru/solrudev/ackpine/compress/archivers/zip/AbstractUnicodeExtraField.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public ZipShort getCentralDirectoryLength() {
9696
if (data == null) {
9797
assembleData();
9898
}
99-
return new ZipShort(data != null ? data.length : 0);
99+
return ZipShort.lengthOf(data);
100100
}
101101

102102
@Override

0 commit comments

Comments
 (0)