JDK-8199912 - jshell /open URL

Christian Stein sormuras at gmail.com
Thu Apr 26 07:31:16 UTC 2018


Hi Michal,

1] I hope so! :)

2] Would a simple `java.nio.Files.copy()` using
`java.net.URL`/`openStream()` suffice?

  try (var stream = new URL(fileUrl).openStream()) {
    Files.copy(stream, target);
  }

Or a `stream.transferTo(target)` where `target` is piped into the `Scanner`
instance.
This would by-pass the dependency to `java.net.http`.

3] Mh, try to create a URI/URL and catch `URISyntaxException` and friends?

4] When using the `URL.openStream` + `transferTo` methods all http responses
are encapsulated in `IOExceptions`.

While typing this response, one could refactor the existing `runFile(...)`
method
to only support URIs, local files are just a special case using the
`file://` protocol.

Cheers,
Christian



On Thu, Apr 26, 2018 at 9:01 AM, Michal Vala <mvala at redhat.com> wrote:

> Hi,
> I've been implementing jshell function to open scripts from url -
> JDK-8199912.
>
> Here's the rough working implementation: https://michalvala.fedorapeopl
> e.org/webrevs/JDK-8199912/webrev.00/
>
> Few questions:
>
> 1] Is this requirement still valid?
> 2] Is dependency on java.net.http module ok?
> 3] Is there any better way how to detect http URL? This is ugly, but I
> haven't find any better example inside jdk.
> 4] Any better way how to handle http response status?
>
>
>
> --
> Michal Vala
> OpenJDK QE
> Red Hat Czech
>


More information about the kulla-dev mailing list