@Test public void testFilterStop() throws IOException { File in = new File("testdata/asciiComment.afp"); AfpFilterChain chain = new AfpFilterChain(in, null); chain.filter(new ChainLink() { private boolean once = false; @Override public boolean onStructuredField(Chain chain, SF sf) throws IOException { if(once) throw new IllegalAccessError(); chain.commit(this, sf); once = true; return false; } @Override public boolean needTwoPass() { return false; } }); }
public void filter(ChainLink... chainLinks) throws IOException { boolean need2Pass = false; for(ChainLink link : chainLinks) { if(link.needTwoPass()) { need2Pass = true; break; } } if(!need2Pass) { doFilter(in, out, chainLinks); return; } LinkedList<ChainLink> links = new LinkedList<ChainLink>(Arrays.asList(chainLinks)); File currentIn = in; File currentOut = null; ChainLink twoPassLink = null; do { LinkedList<ChainLink> toFilter = new LinkedList<ChainLink>(); for(ChainLink link : links) { if(link.needTwoPass() && link != twoPassLink) { twoPassLink = link; break; } toFilter.add(link); } if(!toFilter.isEmpty()) { currentOut = File.createTempFile("filter", ".afp"); currentOut.delete(); currentOut.deleteOnExit(); doFilter(currentIn, currentOut, (ChainLink[]) toFilter.toArray(new ChainLink[toFilter.size()])); if(currentIn != in) { currentIn.delete(); } currentIn = currentOut; } else { doRead(currentIn, twoPassLink); } links.removeAll(toFilter); } while(!links.isEmpty()); copy(currentOut, out); }
AfpFilterChain { public void filter(ChainLink... chainLinks) throws IOException { boolean need2Pass = false; for(ChainLink link : chainLinks) { if(link.needTwoPass()) { need2Pass = true; break; } } if(!need2Pass) { doFilter(in, out, chainLinks); return; } LinkedList<ChainLink> links = new LinkedList<ChainLink>(Arrays.asList(chainLinks)); File currentIn = in; File currentOut = null; ChainLink twoPassLink = null; do { LinkedList<ChainLink> toFilter = new LinkedList<ChainLink>(); for(ChainLink link : links) { if(link.needTwoPass() && link != twoPassLink) { twoPassLink = link; break; } toFilter.add(link); } if(!toFilter.isEmpty()) { currentOut = File.createTempFile("filter", ".afp"); currentOut.delete(); currentOut.deleteOnExit(); doFilter(currentIn, currentOut, (ChainLink[]) toFilter.toArray(new ChainLink[toFilter.size()])); if(currentIn != in) { currentIn.delete(); } currentIn = currentOut; } else { doRead(currentIn, twoPassLink); } links.removeAll(toFilter); } while(!links.isEmpty()); copy(currentOut, out); } }
AfpFilterChain { public void filter(ChainLink... chainLinks) throws IOException { boolean need2Pass = false; for(ChainLink link : chainLinks) { if(link.needTwoPass()) { need2Pass = true; break; } } if(!need2Pass) { doFilter(in, out, chainLinks); return; } LinkedList<ChainLink> links = new LinkedList<ChainLink>(Arrays.asList(chainLinks)); File currentIn = in; File currentOut = null; ChainLink twoPassLink = null; do { LinkedList<ChainLink> toFilter = new LinkedList<ChainLink>(); for(ChainLink link : links) { if(link.needTwoPass() && link != twoPassLink) { twoPassLink = link; break; } toFilter.add(link); } if(!toFilter.isEmpty()) { currentOut = File.createTempFile("filter", ".afp"); currentOut.delete(); currentOut.deleteOnExit(); doFilter(currentIn, currentOut, (ChainLink[]) toFilter.toArray(new ChainLink[toFilter.size()])); if(currentIn != in) { currentIn.delete(); } currentIn = currentOut; } else { doRead(currentIn, twoPassLink); } links.removeAll(toFilter); } while(!links.isEmpty()); copy(currentOut, out); } AfpFilterChain(File in, File out); }
AfpFilterChain { public void filter(ChainLink... chainLinks) throws IOException { boolean need2Pass = false; for(ChainLink link : chainLinks) { if(link.needTwoPass()) { need2Pass = true; break; } } if(!need2Pass) { doFilter(in, out, chainLinks); return; } LinkedList<ChainLink> links = new LinkedList<ChainLink>(Arrays.asList(chainLinks)); File currentIn = in; File currentOut = null; ChainLink twoPassLink = null; do { LinkedList<ChainLink> toFilter = new LinkedList<ChainLink>(); for(ChainLink link : links) { if(link.needTwoPass() && link != twoPassLink) { twoPassLink = link; break; } toFilter.add(link); } if(!toFilter.isEmpty()) { currentOut = File.createTempFile("filter", ".afp"); currentOut.delete(); currentOut.deleteOnExit(); doFilter(currentIn, currentOut, (ChainLink[]) toFilter.toArray(new ChainLink[toFilter.size()])); if(currentIn != in) { currentIn.delete(); } currentIn = currentOut; } else { doRead(currentIn, twoPassLink); } links.removeAll(toFilter); } while(!links.isEmpty()); copy(currentOut, out); } AfpFilterChain(File in, File out); void filter(ChainLink... chainLinks); }
AfpFilterChain { public void filter(ChainLink... chainLinks) throws IOException { boolean need2Pass = false; for(ChainLink link : chainLinks) { if(link.needTwoPass()) { need2Pass = true; break; } } if(!need2Pass) { doFilter(in, out, chainLinks); return; } LinkedList<ChainLink> links = new LinkedList<ChainLink>(Arrays.asList(chainLinks)); File currentIn = in; File currentOut = null; ChainLink twoPassLink = null; do { LinkedList<ChainLink> toFilter = new LinkedList<ChainLink>(); for(ChainLink link : links) { if(link.needTwoPass() && link != twoPassLink) { twoPassLink = link; break; } toFilter.add(link); } if(!toFilter.isEmpty()) { currentOut = File.createTempFile("filter", ".afp"); currentOut.delete(); currentOut.deleteOnExit(); doFilter(currentIn, currentOut, (ChainLink[]) toFilter.toArray(new ChainLink[toFilter.size()])); if(currentIn != in) { currentIn.delete(); } currentIn = currentOut; } else { doRead(currentIn, twoPassLink); } links.removeAll(toFilter); } while(!links.isEmpty()); copy(currentOut, out); } AfpFilterChain(File in, File out); void filter(ChainLink... chainLinks);  }