Last change
on this file since 12937 was 12937, checked in by Don-vip, 7 years ago |
fix #14961 - catch IAE when decoding base64 data
|
-
Property svn:eol-style
set to
native
|
File size:
1.1 KB
|
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 | import org.openstreetmap.josm.tools.bugreport.BugReport;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * Connection for "data:" protocol allowing to read inlined base64 images.
|
---|
15 | * <p>
|
---|
16 | * See <a href="http://stackoverflow.com/a/9388757/2257172">StackOverflow</a>.
|
---|
17 | * @since 10931
|
---|
18 | */
|
---|
19 | public class DataConnection extends URLConnection {
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Constructs a new {@code DataConnection}.
|
---|
23 | * @param u data url
|
---|
24 | */
|
---|
25 | public DataConnection(URL u) {
|
---|
26 | super(u);
|
---|
27 | }
|
---|
28 |
|
---|
29 | @Override
|
---|
30 | public void connect() throws IOException {
|
---|
31 | connected = true;
|
---|
32 | }
|
---|
33 |
|
---|
34 | @Override
|
---|
35 | public InputStream getInputStream() throws IOException {
|
---|
36 | try {
|
---|
37 | return new ByteArrayInputStream(Base64.getDecoder().decode(url.toString().replaceFirst("^.*;base64,", "")));
|
---|
38 | } catch (IllegalArgumentException e) {
|
---|
39 | throw BugReport.intercept(e).put("url", url);
|
---|
40 | }
|
---|
41 | }
|
---|
42 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.