Skip to content

Commit 31cdfa8

Browse files
committed
Rewrite Java9+ references to something that should work in Java 8
1 parent 7b221c1 commit 31cdfa8

File tree

8 files changed

+19
-7
lines changed

8 files changed

+19
-7
lines changed

user/build.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
<target name="compile" description="Compile all class files"
9797
unless="compile.complete">
9898
<gwt.javac
99+
release="8"
99100
excludes="**/EmulatedCharset.java,**/HashCodes.java,**/ConsoleLogger.java,**/NativeRegExp.java,**/SuperDevModeLogger.java">
100101
<src path="super/com/google/gwt/emul/javaemul/internal" />
101102
<classpath>
@@ -224,6 +225,7 @@
224225

225226
<!-- Compile a specific gwt-user jar just for jakarta, which will be only used then to produce gwt-servlet-jakarta.jar -->
226227
<gwt.javac
228+
release="8"
227229
srcdir="${project.build}/jakarta-src"
228230
destdir="${javac.out}-jakarta"
229231
excludes="**/EmulatedCharset.java,**/HashCodes.java,**/ConsoleLogger.java,**/NativeRegExp.java,**/SuperDevModeLogger.java,**/junit/**">

user/src/com/google/gwt/resources/rebind/context/AbstractResourceContext.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424
import com.google.gwt.resources.ext.ResourceGenerator;
2525
import com.google.gwt.resources.ext.ResourceGeneratorUtil;
2626
import com.google.gwt.thirdparty.guava.common.io.BaseEncoding;
27+
import com.google.gwt.thirdparty.guava.common.io.ByteStreams;
2728

2829
import java.io.IOException;
30+
import java.io.InputStream;
2931
import java.net.URL;
3032
import java.net.URLConnection;
3133

@@ -71,7 +73,10 @@ public String deploy(URL resource, String mimeType, boolean forceExternal)
7173
String fileName = ResourceGeneratorUtil.baseName(resource);
7274
try {
7375
URLConnection urlConnection = resource.openConnection();
74-
byte[] bytes = urlConnection.getInputStream().readAllBytes();
76+
final byte[] bytes;
77+
try (InputStream inputStream = urlConnection.getInputStream()) {
78+
bytes = ByteStreams.toByteArray(inputStream);
79+
}
7580
String finalMimeType = (mimeType != null) ? mimeType : urlConnection.getContentType();
7681
return deploy(fileName, finalMimeType, bytes, forceExternal);
7782
} catch (IOException e) {

user/src/com/google/gwt/uibinder/rebind/GwtResourceEntityResolver.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.google.gwt.dev.resource.ResourceOracle;
2121
import com.google.gwt.dev.util.collect.Sets;
2222

23+
import com.google.gwt.thirdparty.guava.common.io.ByteStreams;
2324
import org.xml.sax.EntityResolver;
2425
import org.xml.sax.InputSource;
2526

@@ -75,7 +76,7 @@ public InputSource resolveEntity(String publicId, String systemId) {
7576
if (resource != null) {
7677
String content;
7778
try (InputStream is = resource.openContents()) {
78-
content = new String(is.readAllBytes(), StandardCharsets.UTF_8);
79+
content = new String(ByteStreams.toByteArray(is), StandardCharsets.UTF_8);
7980
} catch (IOException ex) {
8081
logger.log(TreeLogger.ERROR, "Error reading resource: " + resource.getLocation());
8182
throw new RuntimeException(ex);

user/src/com/google/gwt/uibinder/rebind/UiBinderGenerator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.google.gwt.dev.resource.ResourceOracle;
2828
import com.google.gwt.resources.rg.GssResourceGenerator;
2929
import com.google.gwt.resources.rg.GssResourceGenerator.GssOptions;
30+
import com.google.gwt.thirdparty.guava.common.io.ByteStreams;
3031
import com.google.gwt.uibinder.client.UiTemplate;
3132
import com.google.gwt.uibinder.rebind.messages.MessagesWriter;
3233
import com.google.gwt.uibinder.rebind.model.ImplicitClientBundle;
@@ -205,7 +206,7 @@ private Document getW3cDoc(MortalLogger logger, DesignTimeUtils designTime,
205206
String content = designTime.getTemplateContent(templatePath);
206207
if (content == null) {
207208
try (InputStream in = resource.openContents()) {
208-
content = new String(in.readAllBytes(), StandardCharsets.UTF_8);
209+
content = new String(ByteStreams.toByteArray(in), StandardCharsets.UTF_8);
209210
}
210211
}
211212
doc = new W3cDomHelper(logger.getTreeLogger(), resourceOracle).documentFor(content,

user/src/com/google/gwt/user/tools/CommandLineCreatorUtils.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package com.google.gwt.user.tools;
1717

18+
import com.google.gwt.thirdparty.guava.common.io.ByteStreams;
19+
1820
import java.io.File;
1921
import java.io.FileNotFoundException;
2022
import java.io.IOException;
@@ -129,7 +131,7 @@ public static String getFileFromClassPath(String partialPath)
129131
if (in == null) {
130132
throw new FileNotFoundException(partialPath);
131133
}
132-
return new String(in.readAllBytes(), StandardCharsets.UTF_8);
134+
return new String(ByteStreams.toByteArray(in), StandardCharsets.UTF_8);
133135
}
134136
}
135137

user/src/com/google/gwt/user/tools/QuerySourceMap.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static void main(String[] args) throws Exception {
3333
int col = Integer.valueOf(args[2]);
3434

3535
SourceMapping consumer = SourceMapConsumerFactory.parse(
36-
Files.readString(Paths.get(filename), StandardCharsets.UTF_8));
36+
new String(Files.readAllBytes(Paths.get(filename)), StandardCharsets.UTF_8));
3737
System.out.println(consumer.getMappingForLine(line, col));
3838
}
3939
}

user/src/com/google/gwt/user/tools/WebAppCreator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.google.gwt.dev.DevMode;
2222
import com.google.gwt.dev.GwtVersion;
2323
import com.google.gwt.dev.util.collect.HashSet;
24+
import com.google.gwt.thirdparty.guava.common.io.ByteStreams;
2425
import com.google.gwt.thirdparty.guava.common.io.CharStreams;
2526
import com.google.gwt.user.tools.util.ArgHandlerIgnore;
2627
import com.google.gwt.user.tools.util.ArgHandlerOverwrite;
@@ -731,7 +732,7 @@ protected void doRun(String installPath) throws IOException, WebAppCreatorExcept
731732
}
732733
if (fileCreator.isBinary) {
733734
try (FileOutputStream o = new FileOutputStream(file); InputStream i = url.openStream()) {
734-
i.transferTo(o);
735+
ByteStreams.copy(i, o);
735736
}
736737
} else {
737738
try (InputStream i = url.openStream()) {

user/src/com/google/web/bindery/requestfactory/server/RequestFactoryJarExtractor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ public Void call() throws Exception {
507507
String destPath = getPackagePath(state.type) + state.source;
508508
if (sources.add(sourcePath) && loader.exists(sourcePath)) {
509509
try (InputStream is = loader.getResourceAsStream(sourcePath)) {
510-
emitter.emit(destPath, new ByteArrayInputStream(is.readAllBytes()));
510+
emitter.emit(destPath, is);
511511
}
512512
}
513513
}

0 commit comments

Comments
 (0)