@SuppressWarnings("resource") private void walkRecursive(File base, InputStream stream, Multimap<String, ActionIDDef> idsPerFile) throws IOException { ZipInputStream zipStream = new ZipInputStream(stream); while(true) { final ZipEntry entry; try { entry = zipStream.getNextEntry(); } catch (IOException e) { throw new IOException("While handling file: " + base, e); } if(entry == null) { break; } File file = new File(base, entry.getName()); if(ActionIDDef.isActionFile(file)) { idsPerFile.putAll(file.getPath(), ActionIDDef.parse(new CloseShieldInputStream(zipStream), new File(entry.getName()).getName())); } if(ZipUtils.isZip(entry.getName())) { walkRecursive(file, zipStream, idsPerFile); } zipStream.closeEntry(); } }
public FixedLengthInputStream(InputStream stream, long maxLen) { super(new CountingInputStream(new CloseShieldInputStream(stream))); // Save a correctly-typed reference to the underlying stream. this.countingIn = (CountingInputStream) this.in; this.maxBytes = maxLen; }
@Override public Void run() throws Exception { final DocumentFactory factory = new DocumentFactory().configure(options); try (final InputStream input = new CloseShieldInputStream(System.in); final ReportMap reportMap = new ReportMapFactory(options) .withDocumentFactory(factory) .createShared()) { load(factory, reportMap, input); } return null; }
@Override public Void run() throws Exception { final DocumentFactory factory = new DocumentFactory().configure(options); try (final InputStream input = new CloseShieldInputStream(System.in); final DocumentQueue queue = new DocumentQueueFactory(options) .withDocumentFactory(factory) .createShared()) { load(factory, queue, input); } return null; }
private void processMetaData ( final Context context, final InputStream in, final String filename, final String xpath ) throws Exception { // parse input final Document doc = this.xml.newDocumentBuilder ().parse ( new CloseShieldInputStream ( in ) ); final XPathExpression path = this.xml.newXPathFactory ().newXPath ().compile ( xpath ); // filter final NodeList result = XmlHelper.executePath ( doc, path ); // write filtered output final Document fragmentDoc = this.xml.newDocumentBuilder ().newDocument (); Node node = result.item ( 0 ); node = fragmentDoc.adoptNode ( node ); fragmentDoc.appendChild ( node ); // create artifact context.createVirtualArtifact ( filename, out -> { try { XmlHelper.write ( this.xml.newTransformerFactory (), fragmentDoc, new StreamResult ( out ) ); } catch ( final Exception e ) { throw new IOException ( e ); } }, null ); }
@SuppressWarnings("resource") private boolean walkRecursive(File base, InputStream stream, OutputHandler handler) throws IOException { ZipInputStream zipStream = new ZipInputStream(stream); while(true) { final ZipEntry entry; try { entry = zipStream.getNextEntry(); } catch (IOException e) { throw new IOException("While handling file: " + base, e); } if(entry == null) { break; } File file = new File(base, entry.getName()); if(handler.found(file, new CloseShieldInputStream(zipStream))) { return true; } if(ZipUtils.isZip(entry.getName())) { if(walkRecursive(file, zipStream, handler)) { return true; } } zipStream.closeEntry(); } return false; }
public void parse(InputStream is) throws ParseException, HandlerException { try { BAGMutatiesDeelbestandLVC mutaties = objectBuilder.handle(new CloseShieldInputStream(is)); parse(mutaties); } catch (XMLStreamException | FactoryConfigurationError | JAXBException e) { throw new ParseException(e); } }
public void parse(InputStream is) throws ParseException, HandlerException { try { BAGExtractDeelbestandLVC extract = objectBuilder.handle(new CloseShieldInputStream(is)); parse(extract); } catch (XMLStreamException | FactoryConfigurationError | JAXBException e) { throw new ParseException(e); } }
private T generateConfigFromUserPrompt() { System.out.println("Please enter the following fields. Default values are in []."); System.out.println("To use the default value, hit return."); T config = null; try (Scanner s = new Scanner(new CloseShieldInputStream(System.in))) { // Finish setting up the scanner s.useDelimiter(System.lineSeparator()); // Determine if the user wants to change advanced configuration boolean useAdvancedSettings = promptUserForAdvancedSettings(s); // Load fields dynamically from the provided configuration class config = clazz.newInstance(); ArrayList<Entry<Field, Prompt>> fields = getFields(useAdvancedSettings); for (Entry<Field, Prompt> entry : fields) { Field field = entry.getKey(); String message = entry.getValue().message(); field.setAccessible(true); System.out.printf("%s [%s]: ", message, field.get(config)); String input = s.nextLine(); if (!input.isEmpty()) { if (field.getType() == java.lang.Integer.TYPE) { field.set(config, Integer.valueOf(input)); } else { field.set(config, input); } } } } catch (InstantiationException | IllegalAccessException e) { e.printStackTrace(); } return config; }