Skip to content

Commit 6741f68

Browse files
add method to check bgzip
1 parent 3289cd2 commit 6741f68

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package au.csiro.variantspark.utils;
2+
3+
import java.io.BufferedReader;
4+
import java.io.File;
5+
import java.io.InputStreamReader;
6+
import java.io.IOException;
7+
import htsjdk.samtools.util.BlockCompressedInputStream;
8+
9+
public class FileUtils {
10+
11+
/**
12+
*
13+
* @param file: an input file
14+
* @return true if input file is BGZIP by check the first two byte of input file
15+
*/
16+
public static boolean isInputBGZ(final File file) {
17+
18+
try(final BlockCompressedInputStream bgzInputStream = new BlockCompressedInputStream(file)) {
19+
BufferedReader reader = new BufferedReader(new InputStreamReader(bgzInputStream));
20+
String line = reader.readLine();
21+
return line != null && !line.isEmpty();
22+
} catch (IOException e) {
23+
//file is not .vcf.bgz file
24+
return false;
25+
}
26+
}
27+
28+
}

0 commit comments

Comments
 (0)