/** * Test whether the input is the stdin * * @param tool * @return true if input should be stdin, false otherwise. */ public static boolean isStdin(InOutToolOptions tool) { if (tool.getInput() == null && tool.getInputFile() == null) return true; return tool.getInput() != null && tool.getInput().equals("-"); }
/** * @return the force option, whether the output should be overwritten if it * exists */ public boolean overwriteOutput() { return this.isForce(); }
@Override public void validate(AbstractTwitterPreprocessingToolOptions twitterPreprocessingModes) { super.validate(twitterPreprocessingModes); InOutToolOptions.prepareMultivaluedArgument(twitterExtras, "id","created_at"); }
/** * * @param tool options to get data from * @throws CmdLineException */ public static void validateOutput(InOutToolOptions tool) throws CmdLineException { try { if(tool.getOutput() == null) throw new CmdLineException(null,"No Output Specified"); URI outuri = SequenceFileUtility.convertToURI(tool.getOutput()); FileSystem fs = getFileSystem(outuri); Path p = new Path(outuri.toString()); if(fs.exists(p)) { if(tool.overwriteOutput()) { fs.delete(p, true); } else{ // throw new CmdLineException(null, "Output exists, couldn't delete"); System.out.println("Output exists, trying to use what is there..."); } } } catch (IOException e) { throw new CmdLineException(null, "Couldn't delete existing output"); } } /**
if (tool.input == null && tool.getInputFile() == null) { throw new IOException("No valid input provided"); toret.add(f); } else { String[] allinputs = tool.getAllInputs(); for (String floc : allinputs) { File f = new File(floc);
/** * Get the input paths from an {@link InOutToolOptions}. This will resolve the input path * and return either a {@link Path} object representing the string * or, if the path string is a directory, a list of {@link Path}s * representing all the "part" files. * @param options the {@link InOutToolOptions}. * @return the input path * @throws IOException */ public static Path[] getInputPaths(InOutToolOptions options) throws IOException { return SequenceFileUtility.getFilePaths(options.getAllInputs(), "part"); }
/** * @return all the inputs from the -if options file, or the single input if * -i was not defined */ public String[] getAllInputs() { boolean multifiles = this.getInputFile() != null; File inputFileF = null; if (multifiles) { inputFileF = new File(this.getInputFile()); multifiles = inputFileF.exists() && inputFileF.canRead(); } if (!multifiles) { if (this.input == null) return null; return new String[] { this.input }; } else { try { final String[] lines = FileUtils.readlines(inputFileF); return lines; } catch (final IOException e) { if (this.input == null) return null; return new String[] { this.input }; } } }
@Override public void validate(AbstractTwitterPreprocessingToolOptions twitterPreprocessingModes) { super.validate(twitterPreprocessingModes); InOutToolOptions.prepareMultivaluedArgument(twitterExtras, "id","created_at"); }
/** * * @param tool options to get data from * @throws CmdLineException */ public static void validateOutput(InOutToolOptions tool) throws CmdLineException { try { if(tool.getOutput() == null) throw new CmdLineException(null,"No Output Specified"); URI outuri = SequenceFileUtility.convertToURI(tool.getOutput()); FileSystem fs = getFileSystem(outuri); Path p = new Path(outuri.toString()); if(fs.exists(p)) { if(tool.overwriteOutput()) { fs.delete(p, true); } else{ // throw new CmdLineException(null, "Output exists, couldn't delete"); System.out.println("Output exists, trying to use what is there..."); } } } catch (IOException e) { throw new CmdLineException(null, "Couldn't delete existing output"); } } /**
if (tool.input == null && tool.getInputFile() == null) { throw new IOException("No valid input provided"); toret.add(f); } else { String[] allinputs = tool.getAllInputs(); for (String floc : allinputs) { File f = new File(floc);
/** * Get the input paths from an {@link InOutToolOptions}. This will resolve the input path * and return either a {@link Path} object representing the string * or, if the path string is a directory, a list of {@link Path}s * representing all the "part" files. * @param options the {@link InOutToolOptions}. * @return the input path * @throws IOException */ public static Path[] getInputPaths(InOutToolOptions options) throws IOException { return SequenceFileUtility.getFilePaths(options.getAllInputs(), "part"); }
/** * @return all the inputs from the -if options file, or the single input if * -i was not defined */ public String[] getAllInputs() { boolean multifiles = this.getInputFile() != null; File inputFileF = null; if (multifiles) { inputFileF = new File(this.getInputFile()); multifiles = inputFileF.exists() && inputFileF.canRead(); } if (!multifiles) { if (this.input == null) return null; return new String[] { this.input }; } else { try { final String[] lines = FileUtils.readlines(inputFileF); return lines; } catch (final IOException e) { if (this.input == null) return null; return new String[] { this.input }; } } }
/** * prepare the tool for running * * @throws CmdLineException */ public void prepare() throws CmdLineException { final CmdLineParser parser = new CmdLineParser(this); try { if (veryLoud && quiet) { quiet = false; veryLoud = true; } parser.parseArgument(args); InOutToolOptions.prepareMultivaluedArgument(modeOptions); validateFilters(); registerRDFAnalysis(); this.validate(); } catch (final CmdLineException e) { throw e; } }
/** * @param tool * @throws CmdLineException */ public static void validateInput(InOutToolOptions tool) throws CmdLineException { try { FileSystem fs = null ; if(tool.getAllInputs() == null) throw new IOException(); for (String input : tool.getAllInputs()) { URI outuri = SequenceFileUtility.convertToURI(input); if(fs == null) fs = getFileSystem(outuri); if(!fs.exists(new Path(outuri.toString()))) throw new CmdLineException(null, "Couldn't find input file"); } } catch (IOException e) { throw new CmdLineException(null, "Couldn't find input file filesystem"); } }
/** * Test whether the input is the stdin * * @param tool * @return true if input should be stdin, false otherwise. */ public static boolean isStdin(InOutToolOptions tool) { if (tool.getInput() == null && tool.getInputFile() == null) return true; return tool.getInput() != null && tool.getInput().equals("-"); }
/** * @return the force option, whether the output should be overwritten if it * exists */ public boolean overwriteOutput() { return this.isForce(); }
/** * prepare the tool for running * * @throws CmdLineException */ public void prepare() throws CmdLineException { final CmdLineParser parser = new CmdLineParser(this); try { if (veryLoud && quiet) { quiet = false; veryLoud = true; } parser.parseArgument(args); InOutToolOptions.prepareMultivaluedArgument(modeOptions); validateFilters(); registerRDFAnalysis(); this.validate(); } catch (final CmdLineException e) { throw e; } }
/** * Get the output path from an {@link InOutToolOptions}. * @param options the {@link InOutToolOptions}. * @return the output path. */ public static Path getOutputPath(InOutToolOptions options) { return new Path(options.getOutput()); }