@Test public void testProcessFile() throws IOException { final int[] countFiles = { 0 }; UsageDataUtil.processFile(zipItem, new UserInteractionEventCallback() { public boolean visit(UserInteractionEvent uie) { ++countFiles[0]; return true; } }); Assert.assertEquals(18015, countFiles[0]); }
public static void processFile(FileItem file, UserInteractionEventCallback callback) throws IOException { log.debug(String.format("Parsing %s", file.getName())); if (file.getContentType().startsWith("application/zip")) { ZipInputStream zip = new ZipInputStream(file.getInputStream()); ZipEntry ze; int firstDot = file.getName().indexOf("."); if (firstDot == -1 || firstDot == 0) { log.warn("Silently ignoring upload because file name doesn't have '.'"); } final String uid = file.getName().substring(0, firstDot); while((ze = zip.getNextEntry()) != null) { log.debug(String.format("Processing %s", ze.getName())); if (ze.isDirectory()) continue; if (!ze.getName().endsWith(".xml")) continue; processStream(zip, callback, uid); } } else { log.warn(String.format("Silently ignoring upload from someone (not a ZIP file): %s", file.getName())); } }
UsageDataUtil { public static void processFile(FileItem file, UserInteractionEventCallback callback) throws IOException { log.debug(String.format("Parsing %s", file.getName())); if (file.getContentType().startsWith("application/zip")) { ZipInputStream zip = new ZipInputStream(file.getInputStream()); ZipEntry ze; int firstDot = file.getName().indexOf("."); if (firstDot == -1 || firstDot == 0) { log.warn("Silently ignoring upload because file name doesn't have '.'"); } final String uid = file.getName().substring(0, firstDot); while((ze = zip.getNextEntry()) != null) { log.debug(String.format("Processing %s", ze.getName())); if (ze.isDirectory()) continue; if (!ze.getName().endsWith(".xml")) continue; processStream(zip, callback, uid); } } else { log.warn(String.format("Silently ignoring upload from someone (not a ZIP file): %s", file.getName())); } } }
UsageDataUtil { public static void processFile(FileItem file, UserInteractionEventCallback callback) throws IOException { log.debug(String.format("Parsing %s", file.getName())); if (file.getContentType().startsWith("application/zip")) { ZipInputStream zip = new ZipInputStream(file.getInputStream()); ZipEntry ze; int firstDot = file.getName().indexOf("."); if (firstDot == -1 || firstDot == 0) { log.warn("Silently ignoring upload because file name doesn't have '.'"); } final String uid = file.getName().substring(0, firstDot); while((ze = zip.getNextEntry()) != null) { log.debug(String.format("Processing %s", ze.getName())); if (ze.isDirectory()) continue; if (!ze.getName().endsWith(".xml")) continue; processStream(zip, callback, uid); } } else { log.warn(String.format("Silently ignoring upload from someone (not a ZIP file): %s", file.getName())); } } private  UsageDataUtil(); }
UsageDataUtil { public static void processFile(FileItem file, UserInteractionEventCallback callback) throws IOException { log.debug(String.format("Parsing %s", file.getName())); if (file.getContentType().startsWith("application/zip")) { ZipInputStream zip = new ZipInputStream(file.getInputStream()); ZipEntry ze; int firstDot = file.getName().indexOf("."); if (firstDot == -1 || firstDot == 0) { log.warn("Silently ignoring upload because file name doesn't have '.'"); } final String uid = file.getName().substring(0, firstDot); while((ze = zip.getNextEntry()) != null) { log.debug(String.format("Processing %s", ze.getName())); if (ze.isDirectory()) continue; if (!ze.getName().endsWith(".xml")) continue; processStream(zip, callback, uid); } } else { log.warn(String.format("Silently ignoring upload from someone (not a ZIP file): %s", file.getName())); } } private  UsageDataUtil(); static void processFile(FileItem file, UserInteractionEventCallback callback); static void processStream(InputStream is, UserInteractionEventCallback callback, String uid); }
UsageDataUtil { public static void processFile(FileItem file, UserInteractionEventCallback callback) throws IOException { log.debug(String.format("Parsing %s", file.getName())); if (file.getContentType().startsWith("application/zip")) { ZipInputStream zip = new ZipInputStream(file.getInputStream()); ZipEntry ze; int firstDot = file.getName().indexOf("."); if (firstDot == -1 || firstDot == 0) { log.warn("Silently ignoring upload because file name doesn't have '.'"); } final String uid = file.getName().substring(0, firstDot); while((ze = zip.getNextEntry()) != null) { log.debug(String.format("Processing %s", ze.getName())); if (ze.isDirectory()) continue; if (!ze.getName().endsWith(".xml")) continue; processStream(zip, callback, uid); } } else { log.warn(String.format("Silently ignoring upload from someone (not a ZIP file): %s", file.getName())); } } private  UsageDataUtil(); static void processFile(FileItem file, UserInteractionEventCallback callback); static void processStream(InputStream is, UserInteractionEventCallback callback, String uid); static final XStream xs; }