comparison CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/opt/bbmap-39.01-1/current/fileIO/ByteFile.java @ 68:5028fdace37b

planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author jpayne
date Tue, 18 Mar 2025 16:23:26 -0400
parents
children
comparison
equal deleted inserted replaced
67:0e9998148a16 68:5028fdace37b
1 package fileIO;
2 import java.io.File;
3 import java.io.InputStream;
4 import java.util.ArrayList;
5
6 import shared.Shared;
7 import structures.ListNum;
8
9
10 public abstract class ByteFile {
11
12 // public static final ByteFile makeByteFile(String fname){
13 // return makeByteFile(fname, false, true);
14 // }
15
16 public static final ByteFile makeByteFile1(String fname, boolean allowSubprocess){
17 FileFormat ff=FileFormat.testInput(fname, FileFormat.TEXT, null, allowSubprocess, false);
18 return new ByteFile1(ff);
19 }
20
21 public static final ByteFile makeByteFile(String fname, boolean allowSubprocess){
22 FileFormat ff=FileFormat.testInput(fname, FileFormat.TEXT, null, allowSubprocess, false);
23 return makeByteFile(ff);
24 }
25
26 public static final ByteFile makeByteFile(FileFormat ff){
27 return makeByteFile(ff, 0);
28 }
29
30 public static final ByteFile makeByteFile(FileFormat ff, int type){
31 if(type==1){return new ByteFile1(ff);}
32 if(type==2){return new ByteFile2(ff);}
33 if(!Shared.LOW_MEMORY && (FORCE_MODE_BF2 || (!FORCE_MODE_BF1 && Shared.threads()>4/* && (ReadWrite.isCompressed(fname) || ReadWrite.isSam(fname))*/))){
34 // if(allowSubprocess && ((ReadWrite.USE_UNPIGZ || ReadWrite.USE_GUNZIP) && (fname.endsWith(".gz") || fname.endsWith(".gzip")))){}
35 return new ByteFile2(ff);
36 }
37 // if(FORCE_MODE_BF3){return new QuickFile(ff);}
38 return new ByteFile1(ff);
39 }
40
41 protected ByteFile(FileFormat ff_){
42 ff=ff_;
43 assert(ff.read()) : ff;
44 }
45
46 public final ArrayList<byte[]> toByteLines(){
47
48 byte[] s=null;
49 ArrayList<byte[]> list=new ArrayList<byte[]>(4096);
50
51 for(s=nextLine(); s!=null; s=nextLine()){
52 list.add(s);
53 }
54
55 return list;
56 }
57
58 public static final ArrayList<byte[]> toLines(FileFormat ff){
59 ByteFile bf=makeByteFile(ff);
60 ArrayList<byte[]> lines=bf.toByteLines();
61 bf.close();
62 return lines;
63 }
64
65 public static final ArrayList<byte[]> toLines(String fname){
66 FileFormat ff=FileFormat.testInput(fname, FileFormat.TEXT, null, true, false);
67 return toLines(ff);
68 }
69
70 public final long countLines(){
71 byte[] s=null;
72 long count=0;
73 for(s=nextLine(); s!=null; s=nextLine()){count++;}
74 reset();
75
76 return count;
77 }
78
79 public abstract void reset();
80 final void superReset(){
81 nextID=0;
82 }
83
84 public synchronized final ListNum<byte[]> nextList(){
85 byte[] line=nextLine();
86 if(line==null){return null;}
87 ArrayList<byte[]> list=new ArrayList<byte[]>(200);
88 list.add(line);
89 for(int i=1; i<200; i++){
90 line=nextLine();
91 if(line==null){break;}
92 list.add(line);
93 }
94 ListNum<byte[]> ln=new ListNum<byte[]>(list, nextID);
95 nextID++;
96 return ln;
97 }
98
99 public final boolean exists(){
100 return name().equals("stdin") || name().startsWith("stdin.") || name().startsWith("jar:") || new File(name()).exists(); //TODO Ugly and unsafe hack for files in jars
101 }
102
103 public abstract InputStream is();
104 public abstract long lineNum();
105
106 /** Returns true if there was an error */
107 public abstract boolean close();
108
109 public abstract byte[] nextLine();
110
111 // public final void pushBack(byte[] line){
112 // assert(pushBack==null);
113 // pushBack=line;
114 // }
115
116 public abstract void pushBack(byte[] line);
117
118 public abstract boolean isOpen();
119
120 public final String name(){return ff.name();}
121 public final boolean allowSubprocess(){return ff.allowSubprocess();}
122
123 public final FileFormat ff;
124
125 /** Force usage of ByteFile1 */
126 public static boolean FORCE_MODE_BF1=false;//!(Data.GENEPOOL || Data.DENOVO || Data.CORI || Shared.WINDOWS);
127
128 /** Force usage of ByteFile2 */
129 public static boolean FORCE_MODE_BF2=false;
130
131 /** Unused */
132 @Deprecated
133 public static boolean FORCE_MODE_BF3=false;
134
135 protected final static byte slashr='\r', slashn='\n', carrot='>', plus='+', at='@';//, tab='\t';
136
137 // byte[] pushBack=null;
138 private long nextID=0;
139
140 }