source: josm/trunk/src/com/kitfox/svg/app/data/Handler.java@ 4256

Last change on this file since 4256 was 4256, checked in by bastiK, 13 years ago

see #6560 - basic svg support, includes kitfox svgsalamander, r 98, patched

File size: 1.7 KB
Line 
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.kitfox.svg.app.data;
7
8import java.io.ByteArrayInputStream;
9import java.io.IOException;
10import java.io.InputStream;
11import java.net.URL;
12import java.net.URLConnection;
13import java.net.URLStreamHandler;
14
15/**
16 *
17 * @author kitfox
18 */
19public class Handler extends URLStreamHandler
20{
21 class Connection extends URLConnection
22 {
23 String mime;
24 byte[] buf;
25
26 public Connection(URL url)
27 {
28 super(url);
29
30 String path = url.getPath();
31 int idx = path.indexOf(';');
32 mime = path.substring(0, idx);
33 String content = path.substring(idx + 1);
34
35 if (content.startsWith("base64,"))
36 {
37 content = content.substring(7);
38 try {
39 buf = new sun.misc.BASE64Decoder().decodeBuffer(content);
40 } catch (IOException ex) {
41 ex.printStackTrace();
42 }
43 }
44 }
45
46 public void connect() throws IOException
47 {
48 }
49
50 public String getHeaderField(String name)
51 {
52 if ("content-type".equals(name))
53 {
54 return mime;
55 }
56
57 return super.getHeaderField(name);
58 }
59
60 public InputStream getInputStream() throws IOException
61 {
62 return new ByteArrayInputStream(buf);
63 }
64
65// public Object getContent() throws IOException
66// {
67// BufferedImage img = ImageIO.read(getInputStream());
68// }
69 }
70
71 protected URLConnection openConnection(URL u) throws IOException
72 {
73 return new Connection(u);
74 }
75
76}
Note: See TracBrowser for help on using the repository browser.