use of java.io.BufferedInputStream in project bazel by bazelbuild.
the class DataValueFileWithIds method parse.
public static void parse(XMLInputFactory xmlInputFactory, Path source, FullyQualifiedName fileKey, FullyQualifiedName.Factory fqnFactory, KeyValueConsumer<DataKey, DataResource> overwritingConsumer, KeyValueConsumer<DataKey, DataResource> combiningConsumer) throws IOException, XMLStreamException {
ImmutableSet.Builder<String> newIds = ImmutableSet.builder();
try (BufferedInputStream inStream = new BufferedInputStream(Files.newInputStream(source))) {
XMLEventReader eventReader = xmlInputFactory.createXMLEventReader(inStream, StandardCharsets.UTF_8.toString());
// forgiving and allow even non-android namespaced attributes to define a new ID.
while (eventReader.hasNext()) {
XMLEvent event = eventReader.nextEvent();
if (event.isStartElement()) {
StartElement start = event.asStartElement();
Iterator<Attribute> attributes = XmlResourceValues.iterateAttributesFrom(start);
while (attributes.hasNext()) {
Attribute attribute = attributes.next();
String value = attribute.getValue();
if (value.startsWith(SdkConstants.NEW_ID_PREFIX)) {
String idName = value.substring(SdkConstants.NEW_ID_PREFIX.length());
newIds.add(idName);
}
}
}
}
eventReader.close();
} catch (XMLStreamException e) {
throw new XMLStreamException(source + ": " + e.getMessage(), e.getLocation(), e);
} catch (RuntimeException e) {
throw new RuntimeException("Error parsing " + source, e);
}
ImmutableSet<String> idResources = newIds.build();
overwritingConsumer.consume(fileKey, DataValueFile.of(source));
for (String id : idResources) {
combiningConsumer.consume(fqnFactory.create(ResourceType.ID, id), DataResourceXml.createWithNoNamespace(source, IdXmlResourceValue.of()));
}
}
use of java.io.BufferedInputStream in project camel by apache.
the class ManualGenerator method grabBodyContent.
private String grabBodyContent() throws MalformedURLException, IOException {
URL url = new URL(page);
File file = new File(targetDir, ".manualCache-" + url.getFile().substring(1));
try {
HttpURLConnection con = (HttpURLConnection) url.openConnection();
XMLReader parser = new Parser();
parser.setFeature(Parser.namespacesFeature, false);
parser.setFeature(Parser.namespacePrefixesFeature, false);
parser.setProperty(Parser.schemaProperty, new org.ccil.cowan.tagsoup.HTMLSchema() {
{
//problem with nested lists that the confluence {toc} macro creates
elementType("ul", M_LI, M_BLOCK | M_LI, 0);
}
});
StringWriter w = new StringWriter();
XMLWriter xmlWriter = new XMLWriter(w) {
int inDiv = Integer.MAX_VALUE;
int count;
public void characters(char[] ch, int start, int len) throws SAXException {
if (inDiv <= count) {
super.characters(ch, start, len);
}
}
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
count++;
if ("div".equalsIgnoreCase(qName) && "wiki-content maincontent".equalsIgnoreCase(atts.getValue("class"))) {
inDiv = count;
}
if (inDiv <= count) {
super.startElement(uri, localName, qName, atts);
}
}
public void endElement(String uri, String localName, String qName) throws SAXException {
if (inDiv <= count) {
super.endElement(uri, localName, qName);
}
count--;
if (inDiv > count) {
inDiv = Integer.MAX_VALUE;
}
}
};
xmlWriter.setOutputProperty(XMLWriter.OMIT_XML_DECLARATION, "yes");
xmlWriter.setOutputProperty(XMLWriter.METHOD, "html");
parser.setContentHandler(xmlWriter);
long date = con.getLastModified();
parser.parse(new InputSource(new BufferedInputStream(con.getInputStream())));
FileWriter writer = new FileWriter(file);
writer.write(Long.toString(date));
writer.close();
return w.toString();
} catch (Throwable e) {
e.printStackTrace();
throw new RuntimeException("Failed", e);
}
}
use of java.io.BufferedInputStream in project android-classyshark by google.
the class MetaObjectFactory method getMetaObjectFromAar.
private static MetaObject getMetaObjectFromAar(String className, File archiveFile) {
try {
File file = File.createTempFile("classes", "jar");
file.deleteOnExit();
OutputStream out = new FileOutputStream(file);
FileInputStream fin = new FileInputStream(archiveFile);
BufferedInputStream bin = new BufferedInputStream(fin);
ZipInputStream zin = new ZipInputStream(bin);
ZipEntry ze;
while ((ze = zin.getNextEntry()) != null) {
if (ze.getName().endsWith(".jar")) {
byte[] buffer = new byte[8192];
int len;
while ((len = zin.read(buffer)) != -1) {
out.write(buffer, 0, len);
}
out.close();
MetaObject result = getMetaObjectFromJar(className, file);
return result;
}
}
} catch (Exception e) {
}
return new MetaObjectClass(Exception.class);
}
use of java.io.BufferedInputStream in project android-classyshark by google.
the class AarReader method read.
@Override
public void read() {
try {
File file = File.createTempFile("classes", "jar");
file.deleteOnExit();
OutputStream out = new FileOutputStream(file);
FileInputStream fin = new FileInputStream(binaryArchive);
BufferedInputStream bin = new BufferedInputStream(fin);
ZipInputStream zin = new ZipInputStream(bin);
ZipEntry ze;
while ((ze = zin.getNextEntry()) != null) {
if (ze.getName().endsWith(".jar")) {
byte[] buffer = new byte[8192];
int len;
while ((len = zin.read(buffer)) != -1) {
out.write(buffer, 0, len);
}
allClassNames.addAll(JarReader.readClassNamesFromJar(file, this.components));
}
if (ze.getName().equals("AndroidManifest.xml")) {
allClassNames.add("AndroidManifest.xml");
}
}
out.close();
zin.closeEntry();
zin.close();
} catch (Exception e) {
}
}
use of java.io.BufferedInputStream in project android-classyshark by google.
the class DexLoaderBuilder method prepareDex.
private static boolean prepareDex(byte[] bytes, File dexInternalStoragePath) {
BufferedInputStream bis = null;
OutputStream dexWriter = null;
try {
bis = new BufferedInputStream(new ByteArrayInputStream(bytes));
dexWriter = new BufferedOutputStream(new FileOutputStream(dexInternalStoragePath));
byte[] buf = new byte[BUF_SIZE];
int len;
while ((len = bis.read(buf, 0, BUF_SIZE)) > 0) {
dexWriter.write(buf, 0, len);
}
dexWriter.close();
bis.close();
return true;
} catch (IOException e) {
if (dexWriter != null) {
try {
dexWriter.close();
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
}
if (bis != null) {
try {
bis.close();
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
}
return false;
}
}
Aggregations