public void mergeExisting(@NonNull File file) { if (file.isDirectory()) { File[] files = file.listFiles(); if (files != null) { for (File child : files) { mergeExisting(child); } } } else if (file.isFile()) { if (file.getPath().endsWith(DOT_JAR)) { mergeFromJar(file); } else if (file.getPath().endsWith(DOT_XML)) { try { String xml = Files.toString(file, Charsets.UTF_8); mergeAnnotationsXml(file.getPath(), xml); } catch (IOException e) { error("Aborting: I/O problem during transform: " + e.toString()); } } } }
public void mergeExisting(@NonNull File file) { if (file.isDirectory()) { File[] files = file.listFiles(); if (files != null) { for (File child : files) { mergeExisting(child); } } } else if (file.isFile()) { if (file.getPath().endsWith(DOT_JAR)) { mergeFromJar(file); } else if (file.getPath().endsWith(DOT_XML)) { try { String xml = Files.toString(file, Charsets.UTF_8); mergeAnnotationsXml(file.getPath(), xml); } catch (IOException e) { error("Aborting: I/O problem during transform: " + e.toString()); } } } }
private void mergeFromJar(@NonNull File jar) { // Reads in an existing annotations jar and merges in entries found there // with the annotations analyzed from source. JarInputStream zis = null; try { @SuppressWarnings("IOResourceOpenedButNotSafelyClosed") FileInputStream fis = new FileInputStream(jar); zis = new JarInputStream(fis); ZipEntry entry = zis.getNextEntry(); while (entry != null) { if (entry.getName().endsWith(".xml")) { byte[] bytes = ByteStreams.toByteArray(zis); String xml = new String(bytes, Charsets.UTF_8); mergeAnnotationsXml(jar.getPath() + ": " + entry, xml); } entry = zis.getNextEntry(); } } catch (IOException e) { error("Aborting: I/O problem during transform: " + e.toString()); } finally { //noinspection deprecation try { Closeables.close(zis, true /* swallowIOException */); } catch (IOException e) { // cannot happen } } }
private void mergeFromJar(@NonNull File jar) { // Reads in an existing annotations jar and merges in entries found there // with the annotations analyzed from source. JarInputStream zis = null; try { @SuppressWarnings("IOResourceOpenedButNotSafelyClosed") FileInputStream fis = new FileInputStream(jar); zis = new JarInputStream(fis); ZipEntry entry = zis.getNextEntry(); while (entry != null) { if (entry.getName().endsWith(".xml")) { byte[] bytes = ByteStreams.toByteArray(zis); String xml = new String(bytes, Charsets.UTF_8); mergeAnnotationsXml(jar.getPath() + ": " + entry, xml); } entry = zis.getNextEntry(); } } catch (IOException e) { error("Aborting: I/O problem during transform: " + e.toString()); } finally { //noinspection deprecation try { Closeables.close(zis, true /* swallowIOException */); } catch (IOException e) { // cannot happen } } }