Skip to content

Commit c12fd4b

Browse files
committed
[Feature] Lower minSdkVersion to 15.
1 parent 193deaf commit c12fd4b

File tree

7 files changed

+118
-22
lines changed

7 files changed

+118
-22
lines changed

generate.sh

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ cp -r "${SDK_JAVA_SOURCE_ROOT}/java/nio/file" "${LIBRARY_JAVA_SOURCE_ROOT}/java8
1414
find "${LIBRARY_JAVA_SOURCE_ROOT}/java8/nio/file" -iname '*.java' -type f -print0 | xargs -0 sed -Ei \
1515
-e 's/java\.nio\.file/java8.nio.file/g' \
1616
-e 's/java\.time/org.threeten.bp/g' \
17-
-e 's/\bMath(\.floor(Div|Mod))/org.threeten.bp.jdk8.Jdk8Methods\1/g' \
17+
-e 's/\bMath(\.floor(Div|Mod))\b/org.threeten.bp.jdk8.Jdk8Methods\1/g' \
18+
-e 's/\bObjects(\.requireNonNull)\b/org.threeten.bp.jdk8.Jdk8Methods\1/g' \
1819
-e 's/java(\.util\.(Spliterator|function|stream))/java9\1/g' \
1920
-e '/^\s*import(\s+static)?\s+sun\..+\s*;\s*$/d' \
2021

@@ -253,6 +254,16 @@ find "${LIBRARY_JAVA_SOURCE_ROOT}/java8/nio/file" -iname '*.java' -type f -print
253254
-e "s/java(\.nio\.channels\.(File|SeekableByte)Channel)/java8\1/g" \
254255
-e "/^\s*import\s+java\.nio\.channels\.\*\s*;\s*$/a\import java8.nio.channels.FileChannel;\nimport java8.nio.channels.SeekableByteChannel;"
255256

257+
mkdir -p "${LIBRARY_JAVA_SOURCE_ROOT}/java8/nio/charset"
258+
rm -rf "${LIBRARY_JAVA_SOURCE_ROOT}/java8/nio/charset"
259+
mkdir "${LIBRARY_JAVA_SOURCE_ROOT}/java8/nio/charset"
260+
cp "${SDK_JAVA_SOURCE_ROOT}/java/nio/charset/StandardCharsets.java" "${LIBRARY_JAVA_SOURCE_ROOT}/java8/nio/charset/StandardCharsets.java"
261+
sed -Ei \
262+
-e "s/^(\s*package\s+)java(\.nio\.charset\s*;\s*)$/\1java8\2\n\nimport java.nio.charset.*;/" \
263+
"${LIBRARY_JAVA_SOURCE_ROOT}/java8/nio/charset/StandardCharsets.java"
264+
find "${LIBRARY_JAVA_SOURCE_ROOT}/java8/nio/file" -iname '*.java' -type f -print0 | xargs -0 sed -Ei \
265+
-e 's/\bjava(\.nio\.charset\.StandardCharsets)\b/java8\1/g'
266+
256267
mkdir -p "${LIBRARY_JAVA_SOURCE_ROOT}/java8/io"
257268
rm -rf "${LIBRARY_JAVA_SOURCE_ROOT}/java8/io"
258269
mkdir "${LIBRARY_JAVA_SOURCE_ROOT}/java8/io"
@@ -368,6 +379,21 @@ find "${LIBRARY_JAVA_SOURCE_ROOT}/java8/nio/file" -iname '*.java' -type f -print
368379
-e "s/\b([A-Za-z][A-Za-z0-9_]*)\.lines\(\)/java8.io.BufferedReaders.lines(\1)/g"
369380

370381
git apply <<EOF
382+
diff --git a/library/src/main/java/java8/nio/file/DirectoryIteratorException.java b/library/src/main/java/java8/nio/file/DirectoryIteratorException.java
383+
index 7356794..fd0d53d 100644
384+
--- a/library/src/main/java/java8/nio/file/DirectoryIteratorException.java
385+
+++ b/library/src/main/java/java8/nio/file/DirectoryIteratorException.java
386+
@@ -56,7 +56,9 @@ public final class DirectoryIteratorException
387+
* if the cause is {@code null}
388+
*/
389+
public DirectoryIteratorException(IOException cause) {
390+
- super(org.threeten.bp.jdk8.Jdk8Methods.requireNonNull(cause));
391+
+ super(org.threeten.bp.jdk8.Jdk8Methods.requireNonNull(cause).toString());
392+
+
393+
+ initCause(cause);
394+
}
395+
396+
/**
371397
diff --git a/${LIBRARY_JAVA_SOURCE_ROOT}/java8/nio/file/FileSystems.java b/${LIBRARY_JAVA_SOURCE_ROOT}/java8/nio/file/FileSystems.java
372398
index 432f013..cfdaacb 100644
373399
--- a/${LIBRARY_JAVA_SOURCE_ROOT}/java8/nio/file/FileSystems.java

library/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ android {
44
compileSdkVersion 28
55
buildToolsVersion '28.0.3'
66
defaultConfig {
7-
minSdkVersion 21
7+
minSdkVersion 15
88
targetSdkVersion 28
99
versionCode 1
1010
versionName '1.0.0'
@@ -23,6 +23,6 @@ android {
2323

2424
dependencies {
2525
implementation fileTree(dir: 'libs', include: ['*.jar'])
26-
implementation 'com.jakewharton.threetenabp:threetenabp:1.1.1'
27-
implementation 'net.sourceforge.streamsupport:android-retrostreams:1.7.0'
26+
api 'com.jakewharton.threetenabp:threetenabp:1.1.1'
27+
api 'net.sourceforge.streamsupport:android-retrostreams:1.7.0'
2828
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package java8.nio.charset;
26+
27+
import java.nio.charset.*;
28+
29+
/**
30+
* Constant definitions for the standard {@link Charset Charsets}. These
31+
* charsets are guaranteed to be available on every implementation of the Java
32+
* platform.
33+
*
34+
* @see <a href="Charset#standard">Standard Charsets</a>
35+
* @since 1.7
36+
*/
37+
public final class StandardCharsets {
38+
39+
private StandardCharsets() {
40+
throw new AssertionError("No java.nio.charset.StandardCharsets instances for you!");
41+
}
42+
/**
43+
* Seven-bit ASCII, a.k.a. ISO646-US, a.k.a. the Basic Latin block of the
44+
* Unicode character set
45+
*/
46+
public static final Charset US_ASCII = Charset.forName("US-ASCII");
47+
/**
48+
* ISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1
49+
*/
50+
public static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
51+
/**
52+
* Eight-bit UCS Transformation Format
53+
*/
54+
public static final Charset UTF_8 = Charset.forName("UTF-8");
55+
/**
56+
* Sixteen-bit UCS Transformation Format, big-endian byte order
57+
*/
58+
public static final Charset UTF_16BE = Charset.forName("UTF-16BE");
59+
/**
60+
* Sixteen-bit UCS Transformation Format, little-endian byte order
61+
*/
62+
public static final Charset UTF_16LE = Charset.forName("UTF-16LE");
63+
/**
64+
* Sixteen-bit UCS Transformation Format, byte order identified by an
65+
* optional byte-order mark
66+
*/
67+
public static final Charset UTF_16 = Charset.forName("UTF-16");
68+
}

library/src/main/java/java8/nio/file/DirectoryIteratorException.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ public final class DirectoryIteratorException
5656
* if the cause is {@code null}
5757
*/
5858
public DirectoryIteratorException(IOException cause) {
59-
super(Objects.requireNonNull(cause));
59+
super(org.threeten.bp.jdk8.Jdk8Methods.requireNonNull(cause).toString());
60+
61+
initCause(cause);
6062
}
6163

6264
/**

library/src/main/java/java8/nio/file/Files.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
import java.nio.charset.Charset;
4444
import java.nio.charset.CharsetDecoder;
4545
import java.nio.charset.CharsetEncoder;
46-
import java.nio.charset.StandardCharsets;
46+
import java8.nio.charset.StandardCharsets;
4747
import java8.nio.file.attribute.BasicFileAttributeView;
4848
import java8.nio.file.attribute.BasicFileAttributes;
4949
import java8.nio.file.attribute.DosFileAttributes; // javadoc
@@ -849,7 +849,7 @@ public static Path createTempFile(Path dir,
849849
FileAttribute<?>... attrs)
850850
throws IOException
851851
{
852-
return TempFileHelper.createTempFile(Objects.requireNonNull(dir),
852+
return TempFileHelper.createTempFile(org.threeten.bp.jdk8.Jdk8Methods.requireNonNull(dir),
853853
prefix, suffix, attrs);
854854
}
855855

@@ -947,7 +947,7 @@ public static Path createTempDirectory(Path dir,
947947
FileAttribute<?>... attrs)
948948
throws IOException
949949
{
950-
return TempFileHelper.createTempDirectory(Objects.requireNonNull(dir),
950+
return TempFileHelper.createTempDirectory(org.threeten.bp.jdk8.Jdk8Methods.requireNonNull(dir),
951951
prefix, attrs);
952952
}
953953

@@ -2673,7 +2673,7 @@ public static Path walkFileTree(Path start,
26732673
throw new AssertionError("Should not get here");
26742674
}
26752675

2676-
if (Objects.requireNonNull(result) != FileVisitResult.CONTINUE) {
2676+
if (org.threeten.bp.jdk8.Jdk8Methods.requireNonNull(result) != FileVisitResult.CONTINUE) {
26772677
if (result == FileVisitResult.TERMINATE) {
26782678
break;
26792679
} else if (result == FileVisitResult.SKIP_SIBLINGS) {
@@ -2958,7 +2958,7 @@ public static long copy(InputStream in, Path target, CopyOption... options)
29582958
throws IOException
29592959
{
29602960
// ensure not null before opening file
2961-
Objects.requireNonNull(in);
2961+
org.threeten.bp.jdk8.Jdk8Methods.requireNonNull(in);
29622962

29632963
// check for REPLACE_EXISTING
29642964
boolean replaceExisting = false;
@@ -3040,7 +3040,7 @@ public static long copy(InputStream in, Path target, CopyOption... options)
30403040
*/
30413041
public static long copy(Path source, OutputStream out) throws IOException {
30423042
// ensure not null before opening file
3043-
Objects.requireNonNull(out);
3043+
org.threeten.bp.jdk8.Jdk8Methods.requireNonNull(out);
30443044

30453045
try (InputStream in = newInputStream(source)) {
30463046
return copy(in, out);
@@ -3264,7 +3264,7 @@ public static Path write(Path path, byte[] bytes, OpenOption... options)
32643264
throws IOException
32653265
{
32663266
// ensure bytes is not null before opening file
3267-
Objects.requireNonNull(bytes);
3267+
org.threeten.bp.jdk8.Jdk8Methods.requireNonNull(bytes);
32683268

32693269
try (OutputStream out = Files.newOutputStream(path, options)) {
32703270
int len = bytes.length;
@@ -3323,7 +3323,7 @@ public static Path write(Path path, Iterable<? extends CharSequence> lines,
33233323
throws IOException
33243324
{
33253325
// ensure lines is not null before opening file
3326-
Objects.requireNonNull(lines);
3326+
org.threeten.bp.jdk8.Jdk8Methods.requireNonNull(lines);
33273327
CharsetEncoder encoder = cs.newEncoder();
33283328
OutputStream out = newOutputStream(path, options);
33293329
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, encoder))) {

library/src/main/java/java8/nio/file/SimpleFileVisitor.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ protected SimpleFileVisitor() {
5757
public FileVisitResult preVisitDirectory(T dir, BasicFileAttributes attrs)
5858
throws IOException
5959
{
60-
Objects.requireNonNull(dir);
61-
Objects.requireNonNull(attrs);
60+
org.threeten.bp.jdk8.Jdk8Methods.requireNonNull(dir);
61+
org.threeten.bp.jdk8.Jdk8Methods.requireNonNull(attrs);
6262
return FileVisitResult.CONTINUE;
6363
}
6464

@@ -72,8 +72,8 @@ public FileVisitResult preVisitDirectory(T dir, BasicFileAttributes attrs)
7272
public FileVisitResult visitFile(T file, BasicFileAttributes attrs)
7373
throws IOException
7474
{
75-
Objects.requireNonNull(file);
76-
Objects.requireNonNull(attrs);
75+
org.threeten.bp.jdk8.Jdk8Methods.requireNonNull(file);
76+
org.threeten.bp.jdk8.Jdk8Methods.requireNonNull(attrs);
7777
return FileVisitResult.CONTINUE;
7878
}
7979

@@ -87,7 +87,7 @@ public FileVisitResult visitFile(T file, BasicFileAttributes attrs)
8787
public FileVisitResult visitFileFailed(T file, IOException exc)
8888
throws IOException
8989
{
90-
Objects.requireNonNull(file);
90+
org.threeten.bp.jdk8.Jdk8Methods.requireNonNull(file);
9191
throw exc;
9292
}
9393

@@ -104,7 +104,7 @@ public FileVisitResult visitFileFailed(T file, IOException exc)
104104
public FileVisitResult postVisitDirectory(T dir, IOException exc)
105105
throws IOException
106106
{
107-
Objects.requireNonNull(dir);
107+
org.threeten.bp.jdk8.Jdk8Methods.requireNonNull(dir);
108108
if (exc != null)
109109
throw exc;
110110
return FileVisitResult.CONTINUE;

library/src/main/java/java8/nio/file/attribute/FileTime.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private FileTime(long value, TimeUnit unit, Instant instant) {
9393
* @return a {@code FileTime} representing the given value
9494
*/
9595
public static FileTime from(long value, TimeUnit unit) {
96-
Objects.requireNonNull(unit, "unit");
96+
org.threeten.bp.jdk8.Jdk8Methods.requireNonNull(unit, "unit");
9797
return new FileTime(value, unit, null);
9898
}
9999

@@ -121,7 +121,7 @@ public static FileTime fromMillis(long value) {
121121
* @since 1.8
122122
*/
123123
public static FileTime from(Instant instant) {
124-
Objects.requireNonNull(instant, "instant");
124+
org.threeten.bp.jdk8.Jdk8Methods.requireNonNull(instant, "instant");
125125
return new FileTime(0, null, instant);
126126
}
127127

@@ -139,7 +139,7 @@ public static FileTime from(Instant instant) {
139139
* since the epoch (1970-01-01T00:00:00Z); can be negative
140140
*/
141141
public long to(TimeUnit unit) {
142-
Objects.requireNonNull(unit, "unit");
142+
org.threeten.bp.jdk8.Jdk8Methods.requireNonNull(unit, "unit");
143143
if (this.unit != null) {
144144
return unit.convert(this.value, this.unit);
145145
} else {

0 commit comments

Comments
 (0)