/** * @return True if the name of this resource lets believe that the resource contains Gzipped * contents. */ default boolean isGzipped() { return FileSuffix.GZIP.matches(this); }
public static FileSuffix getEnum(final String value) { return suffixFor(value).orElseThrow( () -> new IllegalArgumentException("No file suffix found for " + value)); }
else if (FileSuffix.resourceFilter(FileSuffix.PBF).test(dataSource))
public boolean matches(final Resource resource) { final Optional<FileSuffix> foundSuffix = suffixFor(resource.getName()); return foundSuffix.isPresent() && foundSuffix.get() == this; }
/** * 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()); }
@Test public void testDoesntExistNoMatch() { Assert.assertFalse(FileSuffix.CSV.matches(new FileSuffixTestCaseResource("test.fizzbuzz"))); }
private void loadFromTextResource(final Field field, final CoreTestRule rule, final CreationContext context, final String resourcePath) { final String packageName = rule.getClass().getPackage().getName().replaceAll("\\.", "/"); final String completeName = String.format("%s/%s", packageName, resourcePath); final ClassResource resource = new ClassResource(completeName); FileSuffix.suffixFor(completeName).ifPresent(suffix -> { if (suffix == FileSuffix.GZIP) { resource.setDecompressor(Decompressor.GZIP); } }); try { field.set(rule, new TextAtlasBuilder().read(resource)); } catch (IllegalArgumentException | IllegalAccessException e) { throw new CoreException("Error loading from text resource {}", resourcePath, e); } }
@Override public boolean accept(final Path path) { return path.getName().endsWith(FileSuffix.PBF.toString()); } }
@Test public void testExistsButNoMatch() { Assert.assertFalse(FileSuffix.CSV.matches(new FileSuffixTestCaseResource("test.csv.ext"))); }
final String completeName = String.format("%s/%s", packageName, resourcePath); final ClassResource resource = new ClassResource(completeName); FileSuffix.suffixFor(completeName).ifPresent(suffix ->
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(); } }
@Test public void testMatches() { Assert.assertTrue(FileSuffix.CSV.matches(new FileSuffixTestCaseResource("test.csv"))); } }
/** * 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); }
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()); } } }