use of java.io.PushbackInputStream in project poi by apache.
the class TestOfficeXMLException method confirmIsPOIFS.
private void confirmIsPOIFS(String sampleFileName, boolean expectedResult) throws IOException {
InputStream in = new PushbackInputStream(openSampleStream(sampleFileName), 10);
try {
boolean actualResult;
try {
actualResult = POIFSFileSystem.hasPOIFSHeader(in);
} catch (IOException e) {
throw new RuntimeException(e);
}
assertEquals(expectedResult, actualResult);
} finally {
in.close();
}
}
use of java.io.PushbackInputStream in project poi by apache.
the class TestOfficeXMLException method testFileCorruptionOPOIFS.
public void testFileCorruptionOPOIFS() throws Exception {
// create test InputStream
byte[] testData = { (byte) 1, (byte) 2, (byte) 3 };
InputStream testInput = new ByteArrayInputStream(testData);
// detect header
InputStream in = new PushbackInputStream(testInput, 10);
assertFalse(OPOIFSFileSystem.hasPOIFSHeader(in));
// check if InputStream is still intact
byte[] test = new byte[3];
in.read(test);
assertTrue(Arrays.equals(testData, test));
assertEquals(-1, in.read());
}
use of java.io.PushbackInputStream in project poi by apache.
the class TestOfficeXMLException method testFileCorruption.
public void testFileCorruption() throws Exception {
// create test InputStream
byte[] testData = { (byte) 1, (byte) 2, (byte) 3 };
InputStream testInput = new ByteArrayInputStream(testData);
// detect header
InputStream in = new PushbackInputStream(testInput, 10);
assertFalse(POIFSFileSystem.hasPOIFSHeader(in));
// check if InputStream is still intact
byte[] test = new byte[3];
in.read(test);
assertTrue(Arrays.equals(testData, test));
assertEquals(-1, in.read());
}
use of java.io.PushbackInputStream in project robovm by robovm.
the class CertificateFactory method engineGenerateCertificate.
/**
* Generates a certificate object and initializes it with the data
* read from the input stream inStream.
*/
public java.security.cert.Certificate engineGenerateCertificate(InputStream in) throws CertificateException {
if (currentStream == null) {
currentStream = in;
sData = null;
sDataObjectCount = 0;
} else if (// reset if input stream has changed
currentStream != in) {
currentStream = in;
sData = null;
sDataObjectCount = 0;
}
try {
if (sData != null) {
if (sDataObjectCount != sData.size()) {
return getCertificate();
} else {
sData = null;
sDataObjectCount = 0;
return null;
}
}
PushbackInputStream pis = new PushbackInputStream(in);
int tag = pis.read();
if (tag == -1) {
return null;
}
pis.unread(tag);
if (// assume ascii PEM encoded.
tag != 0x30) {
return readPEMCertificate(pis);
} else {
return readDERCertificate(new ASN1InputStream(pis));
}
} catch (Exception e) {
throw new ExCertificateException(e);
}
}
use of java.io.PushbackInputStream in project robovm by robovm.
the class CertificateFactory method engineGenerateCRL.
/**
* Generates a certificate revocation list (CRL) object and initializes
* it with the data read from the input stream inStream.
*/
public CRL engineGenerateCRL(InputStream inStream) throws CRLException {
if (currentCrlStream == null) {
currentCrlStream = inStream;
sCrlData = null;
sCrlDataObjectCount = 0;
} else if (// reset if input stream has changed
currentCrlStream != inStream) {
currentCrlStream = inStream;
sCrlData = null;
sCrlDataObjectCount = 0;
}
try {
if (sCrlData != null) {
if (sCrlDataObjectCount != sCrlData.size()) {
return getCRL();
} else {
sCrlData = null;
sCrlDataObjectCount = 0;
return null;
}
}
PushbackInputStream pis = new PushbackInputStream(inStream);
int tag = pis.read();
if (tag == -1) {
return null;
}
pis.unread(tag);
if (// assume ascii PEM encoded.
tag != 0x30) {
return readPEMCRL(pis);
} else {
// lazy evaluate to help processing of large CRLs
return readDERCRL(new ASN1InputStream(pis, true));
}
} catch (CRLException e) {
throw e;
} catch (Exception e) {
throw new CRLException(e.toString());
}
}
Aggregations