Last change
on this file since 10931 was 10931, checked in by Don-vip, 8 years ago |
fix #13513 - Registers a protocol handler for data: URLs allowing to display base64-inlined images in HTML help
|
-
Property svn:eol-style
set to
native
|
File size:
951 bytes
|
Line | |
---|
1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io.protocols.data;
|
---|
3 |
|
---|
4 | import java.io.ByteArrayInputStream;
|
---|
5 | import java.io.IOException;
|
---|
6 | import java.io.InputStream;
|
---|
7 | import java.net.URL;
|
---|
8 | import java.net.URLConnection;
|
---|
9 | import java.util.Base64;
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * Connection for "data:" protocol allowing to read inlined base64 images.
|
---|
13 | * <p>
|
---|
14 | * See <a href="http://stackoverflow.com/a/9388757/2257172">StackOverflow</a>.
|
---|
15 | * @since 10931
|
---|
16 | */
|
---|
17 | public class DataConnection extends URLConnection {
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Constructs a new {@code DataConnection}.
|
---|
21 | * @param u data url
|
---|
22 | */
|
---|
23 | public DataConnection(URL u) {
|
---|
24 | super(u);
|
---|
25 | }
|
---|
26 |
|
---|
27 | @Override
|
---|
28 | public void connect() throws IOException {
|
---|
29 | connected = true;
|
---|
30 | }
|
---|
31 |
|
---|
32 | @Override
|
---|
33 | public InputStream getInputStream() throws IOException {
|
---|
34 | return new ByteArrayInputStream(Base64.getDecoder().decode(url.toString().replaceFirst("^.*;base64,", "")));
|
---|
35 | }
|
---|
36 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.