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);
}
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();
}
}
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) {
}
}
}
}
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);
}
}
}
}
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;
}
Aggregations