@Test public void testCharacterEndcoding() throws Exception { InputStream stream = new ByteArrayInputStream(characterDocs.getBytes(StandardCharsets.UTF_8)); AtomicInteger numSent = new AtomicInteger(0); FeedClient feedClient = mock(FeedClient.class); final AtomicBoolean success = new AtomicBoolean(false); doAnswer(new Answer<Object>() { public Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); String docId = (String) args[0]; CharSequence value = (CharSequence)args[1]; assertThat(value.toString(), is( "<document documenttype=\"simple\" documentid=\"id:test::&amp;http: " <language><![CDATA[ja]]></language>\n" + " <title><![CDATA[test document1]]></title>\n" + " <description><![CDATA[Bjørnen' blåbær på øy nærheten.]]></description>\n" + " <date>1091356845</date>\n" + " <surl><![CDATA[http: " </document>")); success.set(true); return null; } }).when(feedClient).stream(anyString(), any()); XmlFeedReader.read(stream, feedClient, numSent); assertThat(numSent.get(), is(1)); assert(success.get()); }
public static void read(InputStream inputStream, FeedClient feedClient, AtomicInteger numSent) throws Exception { SAXParserFactory parserFactory = SAXParserFactory.newInstance(); parserFactory.setFeature("http: parserFactory.setValidating(false); parserFactory.setNamespaceAware(false); SAXParser parser = parserFactory.newSAXParser(); SAXClientFeeder saxClientFeeder = new SAXClientFeeder(feedClient, numSent); InputSource inputSource = new InputSource(); inputSource.setEncoding(StandardCharsets.UTF_8.displayName()); inputSource.setByteStream(inputStream); parser.setProperty("http: parser.parse(inputSource, saxClientFeeder); }
XmlFeedReader { public static void read(InputStream inputStream, FeedClient feedClient, AtomicInteger numSent) throws Exception { SAXParserFactory parserFactory = SAXParserFactory.newInstance(); parserFactory.setFeature("http: parserFactory.setValidating(false); parserFactory.setNamespaceAware(false); SAXParser parser = parserFactory.newSAXParser(); SAXClientFeeder saxClientFeeder = new SAXClientFeeder(feedClient, numSent); InputSource inputSource = new InputSource(); inputSource.setEncoding(StandardCharsets.UTF_8.displayName()); inputSource.setByteStream(inputStream); parser.setProperty("http: parser.parse(inputSource, saxClientFeeder); } }
XmlFeedReader { public static void read(InputStream inputStream, FeedClient feedClient, AtomicInteger numSent) throws Exception { SAXParserFactory parserFactory = SAXParserFactory.newInstance(); parserFactory.setFeature("http: parserFactory.setValidating(false); parserFactory.setNamespaceAware(false); SAXParser parser = parserFactory.newSAXParser(); SAXClientFeeder saxClientFeeder = new SAXClientFeeder(feedClient, numSent); InputSource inputSource = new InputSource(); inputSource.setEncoding(StandardCharsets.UTF_8.displayName()); inputSource.setByteStream(inputStream); parser.setProperty("http: parser.parse(inputSource, saxClientFeeder); } private  XmlFeedReader(); }
XmlFeedReader { public static void read(InputStream inputStream, FeedClient feedClient, AtomicInteger numSent) throws Exception { SAXParserFactory parserFactory = SAXParserFactory.newInstance(); parserFactory.setFeature("http: parserFactory.setValidating(false); parserFactory.setNamespaceAware(false); SAXParser parser = parserFactory.newSAXParser(); SAXClientFeeder saxClientFeeder = new SAXClientFeeder(feedClient, numSent); InputSource inputSource = new InputSource(); inputSource.setEncoding(StandardCharsets.UTF_8.displayName()); inputSource.setByteStream(inputStream); parser.setProperty("http: parser.parse(inputSource, saxClientFeeder); } private  XmlFeedReader(); static void read(InputStream inputStream, FeedClient feedClient, AtomicInteger numSent); }
XmlFeedReader { public static void read(InputStream inputStream, FeedClient feedClient, AtomicInteger numSent) throws Exception { SAXParserFactory parserFactory = SAXParserFactory.newInstance(); parserFactory.setFeature("http: parserFactory.setValidating(false); parserFactory.setNamespaceAware(false); SAXParser parser = parserFactory.newSAXParser(); SAXClientFeeder saxClientFeeder = new SAXClientFeeder(feedClient, numSent); InputSource inputSource = new InputSource(); inputSource.setEncoding(StandardCharsets.UTF_8.displayName()); inputSource.setByteStream(inputStream); parser.setProperty("http: parser.parse(inputSource, saxClientFeeder); } private  XmlFeedReader(); static void read(InputStream inputStream, FeedClient feedClient, AtomicInteger numSent);  }