@Override public Path asPath() { try { return IOUtil.getPath(urlResource.toExternalForm()); } catch (IOException | IllegalArgumentException | FileSystemNotFoundException | SecurityException e) { return null; } }
@Test public void testAddExtensionOnList() throws IOException { Path p = IOUtil.getPath("/folder/file"); List<FileSystemProvider> fileSystemProviders = FileSystemProvider.installedProviders(); List<Path> paths = new ArrayList<>(); List<String> strings = new ArrayList<>(); paths.add(IOUtil.addExtension(p, ".ext")); strings.add("/folder/file.ext"); p = IOUtil.getPath("folder/file"); paths.add(IOUtil.addExtension(p, ".ext")); strings.add("folder/file.ext"); List<Path> expectedPaths = IOUtil.getPaths(strings); Assert.assertEquals(paths, expectedPaths); }
@Override public Path asPath() { try { return IOUtil.getPath(urlResource.toExternalForm()); } catch (IOException | IllegalArgumentException | FileSystemNotFoundException | SecurityException e) { return null; } }
/** * create an index file from the target feature file * * @param featureFile the feature file to create an index from */ public AbstractIndex(final String featureFile) { this(); try { this.indexedPath = IOUtil.getPath(featureFile).toAbsolutePath(); } catch (IOException e) { throw new IllegalArgumentException("IO error: " + e.getMessage(), e); } }
/** * create an index file from the target feature file * * @param featureFile the feature file to create an index from */ public AbstractIndex(final String featureFile) { this(); try { this.indexedPath = IOUtil.getPath(featureFile).toAbsolutePath(); } catch (IOException e) { throw new IllegalArgumentException("IO error: " + e.getMessage(), e); } }
public static List<Path> getPaths(List<String> uriStrings) throws RuntimeIOException { return uriStrings.stream().map(s -> { try { return IOUtil.getPath(s); } catch (IOException e) { throw new RuntimeIOException(e); } }).collect(Collectors.toList()); }
private static Path getVariantPath(final String pathString) { try { return IOUtil.getPath(pathString); } catch (IOException e) { throw new PicardException("Error while converting input " + pathString + " to Path", e); } }
private static Path getVariantPath(final String pathString) { try { return IOUtil.getPath(pathString); } catch (IOException e) { throw new PicardException("Error while converting input " + pathString + " to Path", e); } }
public static List<Path> getPaths(List<String> uriStrings) throws RuntimeIOException { return uriStrings.stream().map(s -> { try { return IOUtil.getPath(s); } catch (IOException e) { throw new RuntimeIOException(e); } }).collect(Collectors.toList()); }
@Override public boolean canDecode( final String path ) { try (InputStream fis = Files.newInputStream(IOUtil.getPath(path)) ){ final BCFVersion version = BCFVersion.readBCFVersion(fis); return version != null && version.getMajorVersion() == ALLOWED_MAJOR_VERSION; } catch ( final IOException e ) { return false; } }
@Override public boolean canDecode( final String path ) { try (InputStream fis = Files.newInputStream(IOUtil.getPath(path)) ){ final BCFVersion version = BCFVersion.readBCFVersion(fis); return version != null && version.getMajorVersion() == ALLOWED_MAJOR_VERSION; } catch ( final IOException e ) { return false; } }
protected String[] customCommandLineValidation() { try { final boolean isBamOrSamFile = isBamOrSam(IOUtil.getPath(INPUT)); if (!isBamOrSamFile && IGNORE_READ_GROUPS) { return new String[]{"The parameter IGNORE_READ_GROUPS can only be used with BAM/SAM inputs."}; } if (isBamOrSamFile && OBSERVED_SAMPLE_ALIAS != null) { return new String[]{"The parameter OBSERVED_SAMPLE_ALIAS can only be used with a VCF input."}; } } catch (IOException e) { e.printStackTrace(); } return super.customCommandLineValidation(); }
/** Returns a default tmp directory as a Path. */ public static Path getDefaultTmpDirPath() { try { final String user = System.getProperty("user.name"); final String tmp = System.getProperty("java.io.tmpdir"); final Path tmpParent = getPath(tmp); if (tmpParent.endsWith(tmpParent.getFileSystem().getSeparator() + user)) { return tmpParent; } else { return tmpParent.resolve(user); } } catch (IOException e) { throw new RuntimeIOException(e); } }
protected String[] customCommandLineValidation() { try { final boolean isBamOrSamFile = isBamOrSam(IOUtil.getPath(INPUT)); if (!isBamOrSamFile && IGNORE_READ_GROUPS) { return new String[]{"The parameter IGNORE_READ_GROUPS can only be used with BAM/SAM inputs."}; } if (isBamOrSamFile && OBSERVED_SAMPLE_ALIAS != null) { return new String[]{"The parameter OBSERVED_SAMPLE_ALIAS can only be used with a VCF input."}; } } catch (IOException e) { e.printStackTrace(); } return super.customCommandLineValidation(); }
public static boolean canDecodeFile(final String potentialInput, final String MAGIC_HEADER_LINE) { try { Path path = IOUtil.getPath(potentialInput); //isVCFStream closes the stream that's passed in return isVCFStream(Files.newInputStream(path), MAGIC_HEADER_LINE) || isVCFStream(new GZIPInputStream(Files.newInputStream(path)), MAGIC_HEADER_LINE) || isVCFStream(new BlockCompressedInputStream(Files.newInputStream(path)), MAGIC_HEADER_LINE); } catch ( FileNotFoundException e ) { return false; } catch ( IOException e ) { return false; } }
public static boolean canDecodeFile(final String potentialInput, final String MAGIC_HEADER_LINE) { try { Path path = IOUtil.getPath(potentialInput); //isVCFStream closes the stream that's passed in return isVCFStream(Files.newInputStream(path), MAGIC_HEADER_LINE) || isVCFStream(new GZIPInputStream(Files.newInputStream(path)), MAGIC_HEADER_LINE) || isVCFStream(new BlockCompressedInputStream(Files.newInputStream(path)), MAGIC_HEADER_LINE); } catch ( FileNotFoundException e ) { return false; } catch ( IOException e ) { return false; } }
@Override public String getPathToDataFile(String path) { try { return Files.readAllLines(IOUtil.getPath(path)).get(0); } catch (IOException e) { throw new RuntimeIOException(e); } } }
@Test(dataProvider = "fofnData") public void testUnrollPaths(final String pathUri, final String[] extensions, final int expectedNumberOfUnrolledPaths) throws IOException { Path p = IOUtil.getPath(pathUri); List<Path> paths = IOUtil.unrollPaths(Collections.singleton(p), extensions); Assert.assertEquals(paths.size(), expectedNumberOfUnrolledPaths); }
@Test public void testAddExtension() throws IOException { Path p = IOUtil.getPath("/folder/file"); Assert.assertEquals(IOUtil.addExtension(p, ".ext"), IOUtil.getPath("/folder/file.ext")); p = IOUtil.getPath("folder/file"); Assert.assertEquals(IOUtil.addExtension(p, ".ext"), IOUtil.getPath("folder/file.ext")); try (FileSystem jimfs = Jimfs.newFileSystem(Configuration.unix())) { p = jimfs.getPath("folder/sub/file"); Assert.assertEquals(IOUtil.addExtension(p, ".ext"), jimfs.getPath("folder/sub/file.ext")); p = jimfs.getPath("folder/file"); Assert.assertEquals(IOUtil.addExtension(p, ".ext"), jimfs.getPath("folder/file.ext")); p = jimfs.getPath("file"); Assert.assertEquals(IOUtil.addExtension(p, ".ext"), jimfs.getPath("file.ext")); } }
@Test public void testIntervalListFrom() throws IOException { final String testPath = TEST_DIR.resolve("IntervalListFromVCFTestComp.interval_list").toString(); final IntervalList fromFileList = IntervalList.fromFile(new File(testPath)); final IntervalList fromPathList = IntervalList.fromPath(IOUtil.getPath(testPath)); fromFileList.getHeader().getSequenceDictionary().assertSameDictionary(fromPathList.getHeader().getSequenceDictionary()); Assert.assertEquals(CollectionUtil.makeCollection(fromFileList.iterator()), CollectionUtil.makeCollection(fromPathList.iterator())); }