/** * Set the output file for the next <code>VariantContextWriter</code> created by this builder. * Determines file type implicitly from the filename. * * @param outPath the file the <code>VariantContextWriter</code> will write to * @return this <code>VariantContextWriterBuilder</code> */ public VariantContextWriterBuilder setOutputPath(final Path outPath) { this.outPath = outPath; this.outStream = null; this.outType = determineOutputTypeFromFile(outPath); return this; }
/** * Set the output file for the next <code>VariantContextWriter</code> created by this builder. * Determines file type implicitly from the filename. * * @param outPath the file the <code>VariantContextWriter</code> will write to * @return this <code>VariantContextWriterBuilder</code> */ public VariantContextWriterBuilder setOutputPath(final Path outPath) { this.outPath = outPath; this.outStream = null; this.outType = determineOutputTypeFromFile(outPath); return this; }
/** * Attempts to determine the type of file/data to write based on the File path being * written to. Will attempt to determine using the logical filename; if that fails it will * attempt to resolve any symlinks and try again. If that fails, and the output file exists * but is neither a file or directory then VCF_STREAM is returned. * * @param file A file whose {@link OutputType} we want to infer * @return The file's {@link OutputType}. Never {@code null}. */ public static OutputType determineOutputTypeFromFile(final File file) { return determineOutputTypeFromFile(file.toPath()); }
/** * Attempts to determine the type of file/data to write based on the File path being * written to. Will attempt to determine using the logical filename; if that fails it will * attempt to resolve any symlinks and try again. If that fails, and the output file exists * but is neither a file or directory then VCF_STREAM is returned. * * @param file A file whose {@link OutputType} we want to infer * @return The file's {@link OutputType}. Never {@code null}. */ public static OutputType determineOutputTypeFromFile(final File file) { return determineOutputTypeFromFile(file.toPath()); }
@Test(dataProvider = "getFilesAndOutputTypes") public void testDetermineOutputType(OutputType expected, File file) { Assert.assertEquals(VariantContextWriterBuilder.determineOutputTypeFromFile(file), expected); }
@Test(dataProvider = "getFilesAndOutputTypes") public void testDetermineOutputTypeOnPath(OutputType expected, File file) { Assert.assertEquals(VariantContextWriterBuilder.determineOutputTypeFromFile(file.toPath()), expected); }
@Test(dataProvider = "getFilesAndOutputTypes") public void testDetermineOutputTypeWithSymlink(OutputType expected, File file) throws IOException { final File link = setUpSymlink(file); Assert.assertEquals(expected, VariantContextWriterBuilder.determineOutputTypeFromFile(link)); }
@Test(dataProvider = "getFilesAndOutputTypes") public void testDetermineOutputTypeWithSymlinkOnPath(OutputType expected, File file) throws IOException { final File link = setUpSymlink(file); Assert.assertEquals(expected, VariantContextWriterBuilder.determineOutputTypeFromFile(link.toPath())); }
final Path canonicalPath = path.toRealPath(); if (!canonicalPath.equals(path)) { return determineOutputTypeFromFile(canonicalPath);
final Path canonicalPath = path.toRealPath(); if (!canonicalPath.equals(path)) { return determineOutputTypeFromFile(canonicalPath);