Search in sources :

Example 56 with BufferedInputStream

use of java.io.BufferedInputStream in project j2objc by google.

the class OldBufferedInputStreamTest method setUp.

@Override
protected void setUp() throws IOException {
    fileName = System.getProperty("user.dir");
    String separator = System.getProperty("file.separator");
    if (fileName.charAt(fileName.length() - 1) == separator.charAt(0)) {
        fileName = Support_PlatformFile.getNewPlatformFile(fileName, "input.tst");
    } else {
        fileName = Support_PlatformFile.getNewPlatformFile(fileName + separator, "input.tst");
    }
    OutputStream fos = new FileOutputStream(fileName);
    fos.write(fileString.getBytes());
    fos.close();
    isFile = new FileInputStream(fileName);
    is = new BufferedInputStream(isFile);
}
Also used : BufferedInputStream(java.io.BufferedInputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) FileInputStream(java.io.FileInputStream)

Example 57 with BufferedInputStream

use of java.io.BufferedInputStream in project j2objc by google.

the class OldAndroidBufferedInputStreamTest method testBufferedInputStream.

public void testBufferedInputStream() throws Exception {
    String str = "AbCdEfGhIjKlM\nOpQrStUvWxYz";
    ByteArrayInputStream aa = new ByteArrayInputStream(str.getBytes());
    ByteArrayInputStream ba = new ByteArrayInputStream(str.getBytes());
    ByteArrayInputStream ca = new ByteArrayInputStream(str.getBytes());
    ByteArrayInputStream da = new ByteArrayInputStream(str.getBytes());
    ByteArrayInputStream ea = new ByteArrayInputStream(str.getBytes());
    BufferedInputStream a = new BufferedInputStream(aa, 6);
    try {
        Assert.assertEquals(str, read(a));
    } finally {
        a.close();
    }
    BufferedInputStream b = new BufferedInputStream(ba, 7);
    try {
        Assert.assertEquals("AbCdEfGhIj", read(b, 10));
    } finally {
        b.close();
    }
    BufferedInputStream c = new BufferedInputStream(ca, 9);
    try {
        assertEquals("bdfhjl\nprtvxz", skipRead(c));
    } finally {
        c.close();
    }
    BufferedInputStream d = new BufferedInputStream(da, 9);
    try {
        assertEquals('A', d.read());
        d.mark(15);
        assertEquals('b', d.read());
        assertEquals('C', d.read());
        d.reset();
        assertEquals('b', d.read());
    } finally {
        d.close();
    }
    BufferedInputStream e = new BufferedInputStream(ea, 11);
    try {
        // test that we can ask for more than is present, and that we'll get
        // back only what is there.
        assertEquals(str, read(e, 10000));
    } finally {
        e.close();
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedInputStream(java.io.BufferedInputStream)

Example 58 with BufferedInputStream

use of java.io.BufferedInputStream in project j2objc by google.

the class TestUtils method getKeyStore.

/**
     * Creates <code>TrustAnchor</code> instance
     * constructed using self signed test certificate
     *
     * @return <code>TrustAnchor</code> instance
     */
//    public static TrustAnchor getTrustAnchor() {
//        CertificateFactory cf = null;
//        try {
//            cf = CertificateFactory.getInstance(certType);
//        } catch (CertificateException e) {
//            // requested cert type is not available in the
//            // default provider package or any of the other provider packages
//            // that were searched
//            throw new RuntimeException(e);
//        }
//        BufferedInputStream bis = null;
//        try {
//            bis = new BufferedInputStream(new ByteArrayInputStream(
//                    getEncodedX509Certificate()));
//            X509Certificate c1 = (X509Certificate)cf.generateCertificate(bis);
//
//            return new TrustAnchor(c1, null);
//        } catch (Exception e) {
//            // all failures are fatal
//            throw new RuntimeException(e);
//        } finally {
//            if (bis != null) {
//                try {
//                    bis.close() ;
//                } catch (IOException ign) {}
//            }
//        }
//    }
/**
     * Creates <code>Set</code> of <code>TrustAnchor</code>s
     * containing single element (self signed test certificate).
     * @return Returns <code>Set</code> of <code>TrustAnchor</code>s
     */
//    public static Set<TrustAnchor> getTrustAnchorSet() {
//        TrustAnchor ta = getTrustAnchor();
//        if (ta == null) {
//            return null;
//        }
//        HashSet<TrustAnchor> set = new HashSet<TrustAnchor>();
//        if (!set.add(ta)) {
//            throw new RuntimeException("Could not create trust anchor set");
//        }
//        return set;
//    }
/**
     * Creates test <code>KeyStore</code> instance
     *
     * @param initialize
     *  Do not initialize returned <code>KeyStore</code> if false
     *
     * @param testKeyStoreType
     *  this parameter ignored if <code>initialize</code> is false;
     *  The following types supported:<br>
     *  1 - <code>KeyStore</code> with untrusted certificates only<br>
     *  2 - <code>KeyStore</code> with trusted certificates only<br>
     *  3 - <code>KeyStore</code> with both trusted and untrusted certificates
     *
     * @return Returns test <code>KeyStore</code> instance
     */
public static KeyStore getKeyStore(boolean initialize, int testKeyStoreType) {
    BufferedInputStream bis = null;
    try {
        KeyStore ks = KeyStore.getInstance(keyStoreType);
        if (initialize) {
            String fileName = keyStoreFileName + testKeyStoreType;
            ks.load(Support_Resources.getResourceStream(fileName), storepass);
        }
        return ks;
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        if (initialize && bis != null) {
            try {
                bis.close();
            } catch (IOException ign) {
            }
        }
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) IOException(java.io.IOException) KeyStore(java.security.KeyStore) IOException(java.io.IOException)

Example 59 with BufferedInputStream

use of java.io.BufferedInputStream in project iosched by google.

the class SVGBuilder method build.

/**
	 * Loads, reads, parses the SVG (or SVGZ).
	 * 
	 * @return the parsed SVG.
	 * @throws SVGParseException if there is an error while parsing.
	 */
public SVG build() throws SVGParseException {
    if (data == null) {
        throw new IllegalStateException("SVG input not specified. Call one of the readFrom...() methods first.");
    }
    try {
        final SVGHandler handler = new SVGHandler();
        handler.setColorSwap(searchColor, replaceColor, overideOpacity);
        handler.setWhiteMode(whiteMode);
        if (strokeColorFilter != null) {
            handler.strokePaint.setColorFilter(strokeColorFilter);
        }
        if (fillColorFilter != null) {
            handler.fillPaint.setColorFilter(fillColorFilter);
        }
        // SVGZ support (based on https://github.com/josefpavlik/svg-android/commit/fc0522b2e1):
        if (!data.markSupported())
            // decorate stream so we can use mark/reset
            data = new BufferedInputStream(data);
        try {
            data.mark(4);
            byte[] magic = new byte[2];
            int r = data.read(magic, 0, 2);
            int magicInt = (magic[0] + ((magic[1]) << 8)) & 0xffff;
            data.reset();
            if (r == 2 && magicInt == GZIPInputStream.GZIP_MAGIC) {
                // Log.d(SVGParser.TAG, "SVG is gzipped");
                GZIPInputStream gin = new GZIPInputStream(data);
                data = gin;
            }
        } catch (IOException ioe) {
            throw new SVGParseException(ioe);
        }
        final SVG svg = SVGParser.parse(new InputSource(data), handler);
        return svg;
    } finally {
        if (closeInputStream) {
            try {
                data.close();
            } catch (IOException e) {
                Log.e(SVGParser.TAG, "Error closing SVG input stream.", e);
            }
        }
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) SVGHandler(com.larvalabs.svgandroid.SVGParser.SVGHandler) InputSource(org.xml.sax.InputSource) BufferedInputStream(java.io.BufferedInputStream) IOException(java.io.IOException)

Example 60 with BufferedInputStream

use of java.io.BufferedInputStream in project j2objc by google.

the class OldBufferedInputStreamTest method test_close.

public void test_close() throws IOException {
    is.close();
    try {
        is.read();
        fail("Test 1: IOException expected when reading after closing " + "the stream.");
    } catch (IOException e) {
    // Expected.
    }
    Support_ASimpleInputStream sis = new Support_ASimpleInputStream(true);
    is = new BufferedInputStream(sis);
    try {
        is.close();
        fail("Test 2: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
    sis.throwExceptionOnNextUse = false;
}
Also used : Support_ASimpleInputStream(tests.support.Support_ASimpleInputStream) BufferedInputStream(java.io.BufferedInputStream) IOException(java.io.IOException)

Aggregations

BufferedInputStream (java.io.BufferedInputStream)1700 FileInputStream (java.io.FileInputStream)854 IOException (java.io.IOException)836 InputStream (java.io.InputStream)707 File (java.io.File)449 BufferedOutputStream (java.io.BufferedOutputStream)228 FileOutputStream (java.io.FileOutputStream)218 DataInputStream (java.io.DataInputStream)168 ByteArrayInputStream (java.io.ByteArrayInputStream)159 FileNotFoundException (java.io.FileNotFoundException)147 URL (java.net.URL)147 ZipEntry (java.util.zip.ZipEntry)123 ByteArrayOutputStream (java.io.ByteArrayOutputStream)112 OutputStream (java.io.OutputStream)100 ZipInputStream (java.util.zip.ZipInputStream)72 GZIPInputStream (java.util.zip.GZIPInputStream)68 ArrayList (java.util.ArrayList)62 HashMap (java.util.HashMap)62 HttpURLConnection (java.net.HttpURLConnection)61 ObjectInputStream (java.io.ObjectInputStream)56