public Builder(String local, String remote) { this.local = local; this.remote = remote; this.exists = LocationUtils.exists(local); }
/** * Return a <code>BufferedReader</code> for the location indicated using the platform default encoding. */ public static final BufferedReader getBufferedReader(String location) throws IOException { return getBufferedReader(location, null); }
/** * Extract a String from the list and open a BufferedReader that can read from it */ protected BufferedReader getBufferedReader(List<String> strings, int index) { String string = strings.get(index); return LocationUtils.getBufferedReaderFromString(string); }
/** * Get the MD5 checksum of the file */ public static String getMD5Checksum(File file) { return getChecksum(getCanonicalPath(file), MD5); }
/** * Throw IllegalArgumentException if any of the locationListings do not exist, or if any of the locations inside any of the locationListings do not exist */ public static final void validateLocationListings(List<String> locationListings) { for (String locationListing : locationListings) { validateLocation(locationListing); List<String> locations = getLocations(locationListing); validateLocations(locations); } }
/** * Get the contents of <code>s</code> as a list of <code>String's</code> one entry per line */ public static final List<String> readLinesFromString(String s) { Reader reader = getBufferedReaderFromString(s); return readLinesAndClose(reader); }
@Override public void execute() { if (NullUtils.isNullOrNone(locationListing)) { logger.info("Skipping execution. Location listing [{}]", locationListing); return; } Assert.notNull(locationListing); Assert.notNull(directory); Assert.isTrue(LocationUtils.exists(locationListing)); logger.info("Copying [{}] -> [{}]", locationListing, LocationUtils.getCanonicalPath(directory)); List<String> locations = LocationUtils.getLocations(locationListing); List<File> files = getFiles(locations); LocationUtils.copyLocationsToFiles(locations, files); logger.info("Copied {} files", locations.size()); }
@Override public void copyLocationToFile(String location, RemoteFile destination) { Assert.notNull(location); Assert.isTrue(LocationUtils.exists(location), location + " does not exist"); InputStream in = null; try { in = LocationUtils.getInputStream(location); copyInputStreamToFile(in, destination); } catch (Exception e) { throw new IllegalStateException(e); } finally { IOUtils.closeQuietly(in); } }
exists = LocationUtils.exists(file); if (!exists) { continue; content = LocationUtils.toString(file, encoding); contains = StringUtils.contains(content, token); if (contains) { mtfr.setAbsolutePath(LocationUtils.getCanonicalPath(file)); mtfr.setContent(content); return mtfr;
@Override public List<String> getObject() throws Exception { return LocationUtils.getLocations(locationListings); }
public static final void addConfigFile(List<String> args, File configFile, File defaultConfigFile) { if (configFile == null) { return; } String defaultPath = LocationUtils.getCanonicalPath(defaultConfigFile); String configFilePath = LocationUtils.getCanonicalPath(configFile); if (!StringUtils.equals(defaultPath, configFilePath)) { logger.debug("SSH config=[{}]", configFilePath); args.add("-F"); args.add(configFilePath); } }
/** * Gets the list of XML documents to ingest. * * @param locationListings the locations to search for XML documents to ingest * * @return the list of XML documents to ingest */ private List<XmlDocCollection> getXmlDocCollectionList(List<String> locationListings) { List<XmlDocCollection> xmlDocCollectionList = Lists.newArrayList(); List<String> locations = LocationUtils.getLocations(locationListings); for (String location : locations) { Preconditions.checkState(StringUtils.endsWith(location.toLowerCase(), XML_SUFFIX), "[%s] is not an XML document", location); Preconditions.checkState(LocationUtils.exists(location), "[%s] does not exist", location); logger.info("[{}]", location); xmlDocCollectionList.add(new LocationXmlDocCollection(location)); } return xmlDocCollectionList; }
@Override public void execute() { logger.info("Copying [{}] -> [{}]", locationListing, LocationUtils.getCanonicalPath(directory)); List<String> locations = LocationUtils.getLocations(locationListing); List<File> files = getFiles(locations); LocationUtils.copyLocationsToFiles(locations, files); logger.info("Copied {} files", locations.size()); }
/** * Null safe method for determining if <code>location</code> exists. */ public static final boolean exists(File file) { if (file == null) { return false; } String location = getCanonicalPath(file); if (isExistingFile(location)) { return true; } else { Resource resource = getResource(location); return resource.exists(); } }
public static final List<String> readLinesAndClose(InputStream in, String encoding) { Reader reader = null; try { reader = getBufferedReader(in, encoding); return readLinesAndClose(reader); } catch (IOException e) { throw new IllegalStateException("Unexpected IO error", e); } finally { IOUtils.closeQuietly(reader); } }
/** * Return a <code>BufferedReader</code> for the location indicated using the encoding indicated. */ public static final BufferedReader getBufferedReader(String location, String encoding) throws IOException { try { InputStream in = getInputStream(location); return getBufferedReader(in, encoding); } catch (IOException e) { throw new IOException("Unexpected IO error", e); } }
/** * Get the contents of <code>file</code> as a <code>String</code> using the specified character encoding. */ public static final String toString(File file, String encoding) { return toString(getCanonicalPath(file), encoding); }
public static TextMetaData getTextMetaData(File file) { return getTextMetaData(getCanonicalPath(file)); }
@Override public ConversionResult convert(ConversionContext context) { logger.debug("Converting {}", LocationUtils.getCanonicalPath(context.getOldFile())); File newFile = context.getNewFile(); File oldFile = context.getOldFile(); DefaultSqlReader reader = new DefaultSqlReader(context.getDelimiter()); BufferedReader in = null; OutputStream out = null; try { in = LocationUtils.getBufferedReader(oldFile, context.getEncoding()); out = FileUtils.openOutputStream(newFile); return convert(context, reader, in, out); } catch (IOException e) { throw new IllegalStateException("Unexpected IO error"); } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } }
protected static String getCanonicalLocation(String location) { if (LocationUtils.isExistingFile(location)) { return LocationUtils.getCanonicalPath(new File(location)); } else { return location; } }