source: josm/trunk/src/org/openstreetmap/josm/io/protocols/data/DataConnection.java@ 10931

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.
2package org.openstreetmap.josm.io.protocols.data;
3
4import java.io.ByteArrayInputStream;
5import java.io.IOException;
6import java.io.InputStream;
7import java.net.URL;
8import java.net.URLConnection;
9import 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 */
17public 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.