| 1 |
package jgi; |
| 2 |
|
| 3 |
import java.io.IOException; |
| 4 |
import java.io.InputStream; |
| 5 |
import java.io.OutputStream; |
| 6 |
|
| 7 |
import dna.Data; |
| 8 |
import fileIO.PipeThread; |
| 9 |
import fileIO.ReadWrite; |
| 10 |
import shared.Shared; |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
public class RedirectTest { |
| 18 |
|
| 19 |
public static void main(String[] args) throws IOException{ |
| 20 |
|
| 21 |
String fin=args[0]; |
| 22 |
|
| 23 |
|
| 24 |
System.out.println("fin="+fin); |
| 25 |
|
| 26 |
InputStream in=null; |
| 27 |
final OutputStream os=System.out; |
| 28 |
InputStream es=null; |
| 29 |
Process p=null; |
| 30 |
|
| 31 |
System.out.println("Samtools="+Data.SAMTOOLS()); |
| 32 |
System.out.println("Gzip="+Data.GZIP()); |
| 33 |
System.out.println("Pigz="+Data.PIGZ()); |
| 34 |
System.out.println("Gunzip="+Data.GUNZIP()); |
| 35 |
|
| 36 |
if(Shared.WINDOWS){ |
| 37 |
System.out.println("WINDOWS"); |
| 38 |
in=ReadWrite.getInputStream(fin, false, false); |
| 39 |
}else{ |
| 40 |
System.out.println("LINUX"); |
| 41 |
p=Runtime.getRuntime().exec("gunzip -c -d "+fin); |
| 42 |
in=p.getInputStream(); |
| 43 |
es=p.getErrorStream(); |
| 44 |
assert(es!=null); |
| 45 |
PipeThread et=new PipeThread(es, System.err); |
| 46 |
et.start(); |
| 47 |
System.out.println(p); |
| 48 |
} |
| 49 |
|
| 50 |
final byte[] buf=new byte[4096]; |
| 51 |
for(int len=in.read(buf); len>0; len=in.read(buf)){ |
| 52 |
os.write(buf, 0, len); |
| 53 |
} |
| 54 |
|
| 55 |
in.close(); |
| 56 |
if(es!=null){es.close();} |
| 57 |
ReadWrite.close(os); |
| 58 |
|
| 59 |
} |
| 60 |
|
| 61 |
public static void main_0(String[] args) throws IOException{ |
| 62 |
|
| 63 |
String fin=args[0]; |
| 64 |
String fout=args[1]; |
| 65 |
|
| 66 |
InputStream in=ReadWrite.getInputStream(fin, false, false); |
| 67 |
|
| 68 |
OutputStream os=System.out; |
| 69 |
|
| 70 |
byte[] buf=new byte[4096]; |
| 71 |
|
| 72 |
for(int len=in.read(buf); len>0; len=in.read(buf)){ |
| 73 |
os.write(buf, 0, len); |
| 74 |
} |
| 75 |
|
| 76 |
} |
| 77 |
|
| 78 |
} |