summaryrefslogtreecommitdiffstats
path: root/src/test/java/com/kitfox/svg/zip/ZipTestMain.java
blob: 71929084419078c722c4c08bdd2d8e5e0d31f17e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
 * ZipTestMain.java
 *
 * Created on July 18, 2007, 12:44 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.kitfox.svg.zip;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.zip.GZIPInputStream;

/**
 *
 * @author kitfox
 */
public class ZipTestMain
{
    
    /** Creates a new instance of ZipTestMain */
    public ZipTestMain() throws IOException
    {
        URL url = ZipTestMain.class.getResource("/missing.svgz");
//        URL url = ZipTestMain.class.getResource("/AdamTagletClasses.svg");
        InputStream is = url.openStream();
        BufferedInputStream bin = new BufferedInputStream(is);
        
        bin.mark(2);
        int b0 = bin.read();
        int b1 = bin.read();
        bin.reset();
        
        InputStreamReader reader;
        
        //Check for gzip magic number
        if ((b1 << 8 | b0) == GZIPInputStream.GZIP_MAGIC)
        {
            GZIPInputStream iis = new GZIPInputStream(bin);
            reader = new InputStreamReader(iis);
        }
        else
        {
            //Plain text
            reader = new InputStreamReader(bin);
        }
        
        
        BufferedReader br = new BufferedReader(reader);
        for (String s = br.readLine(); s != null; s = br.readLine())
        {
            System.err.println(s);
        }
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        try
        {
            new ZipTestMain();
        } catch (IOException ex)
        {
            ex.printStackTrace();
        }
    }
    
}