@Override public boolean accept(final Path path) { return path.getName().endsWith(FileSuffix.PBF.toString()); } }
public static Optional<FileSuffix> suffixFor(final String value) { final String compareMe = value.toLowerCase(); return Stream.of(FileSuffix.values()) .filter(suffix -> compareMe.endsWith(suffix.toString())).findFirst(); }
public File(final java.io.File file) { this.javaFile = file; if (file.getAbsolutePath().endsWith(FileSuffix.GZIP.toString())) { this.setCompressor(Compressor.GZIP); this.setDecompressor(Decompressor.GZIP); } if (this.javaFile.getParentFile() != null) { this.javaFile.getParentFile().mkdirs(); } }
/** * Creates a Challenge based on a JSON resource file * * @param checkName * The name of the check that will look for the json challenge info * @return The challenge based from the resource json file */ public static Challenge fromResource(final String checkName) { final ClassResource challenge = new ClassResource(checkName + FileSuffix.JSON.toString()); return challenge.getJSONResourceObject(Survey.class); }
/** * Default constructor * * @param label * label for the metric file * @param fileHelper * {@link SparkFileHelper} for I/O operations * @param outputFolder * output folder path to write files to */ public MetricFileGenerator(final String label, final SparkFileHelper fileHelper, final String outputFolder) { super(fileHelper, outputFolder); final Optional<FileSuffix> knownSuffix = Arrays.stream(FileSuffix.values()) .filter(suffix -> label.endsWith(suffix.toString())).findFirst(); if (knownSuffix.isPresent()) { this.label = label.substring(0, label.lastIndexOf(String.valueOf(knownSuffix.get()))); this.suffix = knownSuffix.get(); } else { this.label = label; this.suffix = FileSuffix.CSV; } // This will make sure we have a header for the csv file this.process(MetricEvent.header()); }
public static File temporary() { return new Retry(1, Duration.ZERO).run(() -> { try { return new File(java.io.File.createTempFile( String.valueOf(RANDOM.nextInt(Integer.MAX_VALUE)), FileSuffix.TEMPORARY.toString())); } catch (final IOException e) { throw new CoreException("Unable to get temporary file.", e); } }); }
private void convertAtlases(final Path atlasDirectory, final Path geojsonDirectory) { final List<File> atlases = fetchAtlasFilesInDirectory(atlasDirectory); atlases.parallelStream().forEach(atlasFile -> { final Time time = Time.now(); final Atlas atlas = ATLAS_RESOURCE_LOADER.load(atlasFile); final String name = FilenameUtils.removeExtension(atlasFile.getName()) + FileSuffix.GEO_JSON.toString(); final File geojsonFile = new File(geojsonDirectory.resolve(name).toFile()); atlas.saveAsLineDelimitedGeoJsonFeatures(geojsonFile, ENTITY_PREDICATE, this.jsonMutator); logger.info("Saved {} in {}.", name, time.elapsedSince()); }); } }
private void compare(final Atlas beforeAtlas, final Atlas afterAtlas, final Path outputDirectory) { final String name = FilenameUtils.removeExtension(beforeAtlas.getName()); final AtlasDelta delta = new AtlasDelta(beforeAtlas, afterAtlas).generate(); final String text = delta.toDiffViewFriendlyString(); final File textFile = new File( outputDirectory.resolve(name + FileSuffix.TEXT.toString()).toFile()); textFile.writeAndClose(text); this.logger.info("Saved text file {}", textFile); final String geoJson = delta.toGeoJson(); final File geoJsonFile = new File( outputDirectory.resolve(name + FileSuffix.GEO_JSON.toString()).toFile()); geoJsonFile.writeAndClose(geoJson); this.logger.info("Saved GeoJSON file {}", geoJsonFile); final String relationsGeoJson = delta.toRelationsGeoJson(); final String relationsGeoJsonFileName = name + "_relations" + FileSuffix.GEO_JSON.toString(); final File relationsGeoJsonFile = new File( outputDirectory.resolve(relationsGeoJsonFileName).toFile()); relationsGeoJsonFile.writeAndClose(relationsGeoJson); this.logger.info("Saved Relations GeoJSON file {}", relationsGeoJsonFile); }
private void removeAllAtlasFiles(final String inputFile) { try { Files.list(Paths.get(inputFile)).forEach(name -> { if (name.getFileName().toString().contains(FileSuffix.ATLAS.toString())) { new File(name.toAbsolutePath().toString()).delete(); } }); } catch (final IOException e) { logger.error("Error deleting files" + e.getMessage()); } } }
protected Iterable<PropertiesLocated> readGeoJsonItems(final Mode mode, final Iterable<File> files, final String filePrefix) { switch (mode) { case FILE: return Iterables.stream(files) .filter(file -> file.getName().endsWith(FileSuffix.GEO_JSON.toString())) .flatMap(this::readGeoJsonItems); case LINE: return Iterables.stream(files).filter(file -> file.getName().startsWith(filePrefix)) .flatMap(file -> file.lines()).map(line -> line.trim()) .filter(line -> !line.isEmpty()).flatMap(this::readGeoJsonItems); default: throw new CoreException("Invalid Mode"); } }