@Test public void testProcessStream() throws IOException { final int[] countFiles = { 0 }; UsageDataUtil.processStream(getClass().getClassLoader().getResourceAsStream(xmlName), new UserInteractionEventCallback() { public boolean visit(UserInteractionEvent uie) { ++countFiles[0]; return true; } }, "uid"); Assert.assertEquals(18015, countFiles[0]); }
public static void processStream(InputStream is, UserInteractionEventCallback callback, String uid) { ByteArrayOutputStream os = new ByteArrayOutputStream(); try { IOUtils.copy(is, os); } catch (IOException e1) { log.error("Unable to read input stream", e1); return; } String xml = null; try { xml = "<list>" + os.toString(FilePart.DEFAULT_CHARSET) + "</list>"; } catch (UnsupportedEncodingException e1) { log.error("Unable to read input stream", e1); return; } try { Object o = xs.fromXML(xml); if (o != null && o instanceof List<?>) { List<?> events = (List<?>) o; for (Object event : events) { if(!callback.visit(new UserInteractionEvent((InteractionEvent) event, uid))) { break; } } } } catch(BaseException e) { log.error("Unable to deserialize XML", e); } }
UsageDataUtil { public static void processStream(InputStream is, UserInteractionEventCallback callback, String uid) { ByteArrayOutputStream os = new ByteArrayOutputStream(); try { IOUtils.copy(is, os); } catch (IOException e1) { log.error("Unable to read input stream", e1); return; } String xml = null; try { xml = "<list>" + os.toString(FilePart.DEFAULT_CHARSET) + "</list>"; } catch (UnsupportedEncodingException e1) { log.error("Unable to read input stream", e1); return; } try { Object o = xs.fromXML(xml); if (o != null && o instanceof List<?>) { List<?> events = (List<?>) o; for (Object event : events) { if(!callback.visit(new UserInteractionEvent((InteractionEvent) event, uid))) { break; } } } } catch(BaseException e) { log.error("Unable to deserialize XML", e); } } }
UsageDataUtil { public static void processStream(InputStream is, UserInteractionEventCallback callback, String uid) { ByteArrayOutputStream os = new ByteArrayOutputStream(); try { IOUtils.copy(is, os); } catch (IOException e1) { log.error("Unable to read input stream", e1); return; } String xml = null; try { xml = "<list>" + os.toString(FilePart.DEFAULT_CHARSET) + "</list>"; } catch (UnsupportedEncodingException e1) { log.error("Unable to read input stream", e1); return; } try { Object o = xs.fromXML(xml); if (o != null && o instanceof List<?>) { List<?> events = (List<?>) o; for (Object event : events) { if(!callback.visit(new UserInteractionEvent((InteractionEvent) event, uid))) { break; } } } } catch(BaseException e) { log.error("Unable to deserialize XML", e); } } private  UsageDataUtil(); }
UsageDataUtil { public static void processStream(InputStream is, UserInteractionEventCallback callback, String uid) { ByteArrayOutputStream os = new ByteArrayOutputStream(); try { IOUtils.copy(is, os); } catch (IOException e1) { log.error("Unable to read input stream", e1); return; } String xml = null; try { xml = "<list>" + os.toString(FilePart.DEFAULT_CHARSET) + "</list>"; } catch (UnsupportedEncodingException e1) { log.error("Unable to read input stream", e1); return; } try { Object o = xs.fromXML(xml); if (o != null && o instanceof List<?>) { List<?> events = (List<?>) o; for (Object event : events) { if(!callback.visit(new UserInteractionEvent((InteractionEvent) event, uid))) { break; } } } } catch(BaseException e) { log.error("Unable to deserialize XML", e); } } private  UsageDataUtil(); static void processFile(FileItem file, UserInteractionEventCallback callback); static void processStream(InputStream is, UserInteractionEventCallback callback, String uid); }
UsageDataUtil { public static void processStream(InputStream is, UserInteractionEventCallback callback, String uid) { ByteArrayOutputStream os = new ByteArrayOutputStream(); try { IOUtils.copy(is, os); } catch (IOException e1) { log.error("Unable to read input stream", e1); return; } String xml = null; try { xml = "<list>" + os.toString(FilePart.DEFAULT_CHARSET) + "</list>"; } catch (UnsupportedEncodingException e1) { log.error("Unable to read input stream", e1); return; } try { Object o = xs.fromXML(xml); if (o != null && o instanceof List<?>) { List<?> events = (List<?>) o; for (Object event : events) { if(!callback.visit(new UserInteractionEvent((InteractionEvent) event, uid))) { break; } } } } catch(BaseException e) { log.error("Unable to deserialize XML", e); } } private  UsageDataUtil(); static void processFile(FileItem file, UserInteractionEventCallback callback); static void processStream(InputStream is, UserInteractionEventCallback callback, String uid); static final XStream xs; }