Changeset 5198
- Timestamp:
- Dec 15, 2009, 1:56:17 PM (13 years ago)
- Location:
- trunk/src/core/net/sf/basedb/util/bfs
- Files:
-
- 4 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/net/sf/basedb/util/bfs/AnnotationWriter.java
r5194 r5198 22 22 package net.sf.basedb.util.bfs; 23 23 24 import java.io.OutputStream; 25 import java.io.OutputStreamWriter; 24 26 import java.io.Writer; 27 import java.nio.charset.Charset; 25 28 import java.util.HashSet; 26 29 import java.util.Set; … … 39 42 { 40 43 44 /** 45 Utility method for creating an annotation writer when you have an 46 output stream. 47 @param out The output stream the annotation writer should print to 48 @param filename Optional, the name of the file the output stream 49 is printing to 50 */ 51 public static AnnotationWriter create(OutputStream out, String filename) 52 { 53 AnnotationWriter writer = new AnnotationWriter( 54 new OutputStreamWriter(out, Charset.forName("UTF-8"))); 55 writer.setFilename(filename); 56 return writer; 57 } 58 59 private String filename; 41 60 private boolean hasPrintedHeaders; 42 61 private int columnCount = -1; … … 53 72 54 73 /** 74 Get the file name that this writer is printing to. 75 @return The file name or null if not known 76 */ 77 public String getFilename() 78 { 79 return filename; 80 } 81 82 /** 83 Set the file name that this writer is printing to. 84 */ 85 public void setFilename(String filename) 86 { 87 this.filename = filename; 88 } 89 90 91 /** 55 92 Checks if headers has already been printed or not. 56 93 */ … … 87 124 if (hasPrintedHeaders()) 88 125 { 89 throw new IllegalStateException("Headers has already been printed"); 90 } 91 if (headers == null) throw new NullPointerException("headers"); 126 throw new IllegalStateException("Headers has already been printed to file: " + 127 getFilename()); 128 } 129 if (headers == null) 130 { 131 throw new NullPointerException("'headers' in file: " + getFilename()); 132 } 92 133 93 134 Set<String> used = new HashSet<String>(); … … 96 137 { 97 138 String header = headers[i]; 98 if (header == null) throw new NullPointerException("headers[" + i + "]"); 139 if (header == null) 140 { 141 throw new NullPointerException("'headers[" + i + "]' in file: " + getFilename()); 142 } 99 143 if (used.contains(header)) 100 144 { 101 throw new IllegalArgumentException("Duplicate header at index " + i + ": " + header); 145 throw new IllegalArgumentException("Duplicate header at index " + i + 146 " in file " + getFilename() + ": " + header); 102 147 } 103 148 used.add(header); … … 127 172 if (!hasPrintedHeaders()) 128 173 { 129 throw new IllegalStateException("Must print headers before printing data"); 174 throw new IllegalStateException("Must print headers before printing data to file: " + 175 getFilename()); 130 176 } 131 177 if (id <= 0) 132 178 { 133 throw new IllegalArgumentException("The id must be a positive integer"); 179 throw new IllegalArgumentException("The id must be a positive integer in file: " + 180 getFilename()); 134 181 } 135 182 if (usedIds.contains(id)) 136 183 { 137 throw new IllegalArgumentException("Id value must be unique: " + id); 138 } 139 if (data == null) throw new NullPointerException("data"); 184 throw new IllegalArgumentException("Id value must be unique in file " + 185 getFilename() + ": " + id); 186 } 187 if (data == null) throw new NullPointerException("'data' in file: " + getFilename()); 140 188 if (data.length != columnCount) 141 189 { 142 190 throw new IllegalArgumentException("Data array has " + data.length + " columns; " + 143 "; expected " + columnCount );191 "; expected " + columnCount + " in file: " + getFilename()); 144 192 } 145 193 usedIds.add(id); -
trunk/src/core/net/sf/basedb/util/bfs/DataWriter.java
r5194 r5198 43 43 { 44 44 45 private String filename; 45 46 private boolean lockedColumns; 46 47 private int columnCount = -1; … … 58 59 } 59 60 61 /** 62 Get the file name that this writer is printing to. 63 @return The file name or null if not known 64 */ 65 public String getFilename() 66 { 67 return filename; 68 } 69 70 /** 71 Set the file name that this writer is printing to. 72 */ 73 public void setFilename(String filename) 74 { 75 this.filename = filename; 76 } 77 60 78 /** 61 79 Get the number of data columns. This information is only … … 82 100 if (lockedColumns) 83 101 { 84 throw new IllegalStateException("Can't change the number of columns since data has already been written"); 102 throw new IllegalStateException("Can't change the number of columns since data " + 103 "has already been written in file: " + getFilename()); 85 104 } 86 105 this.columnCount = columns; … … 111 130 { 112 131 113 if (data == null) throw new NullPointerException(" data");132 if (data == null) throw new NullPointerException("'data' in file: " + getFilename()); 114 133 if (columnCount <= 0) columnCount = data.length; 115 134 if (data.length != columnCount) 116 135 { 117 136 throw new IllegalArgumentException("Data array has " + data.length + " columns; " + 118 "; expected " + columnCount );137 "; expected " + columnCount + " in file: " + getFilename()); 119 138 } 120 139 lockedColumns = true; -
trunk/src/core/net/sf/basedb/util/bfs/MetadataWriter.java
r5194 r5198 22 22 package net.sf.basedb.util.bfs; 23 23 24 import java.io.OutputStream; 25 import java.io.OutputStreamWriter; 24 26 import java.io.PrintWriter; 25 27 import java.io.Writer; 28 import java.nio.charset.Charset; 26 29 import java.util.HashSet; 27 30 import java.util.Set; … … 55 58 public static final String BOF_MARKER = "BFSformat"; 56 59 60 /** 61 Utility method for creating a metadata writer when you have an 62 output stream. 63 @param out The output stream the metadata writer should print to 64 @param filename Optional, the name of the file the output stream 65 is printing to 66 */ 67 public static MetadataWriter create(OutputStream out, String filename) 68 { 69 MetadataWriter writer = new MetadataWriter( 70 new OutputStreamWriter(out, Charset.forName("UTF-8"))); 71 writer.setFilename(filename); 72 return writer; 73 } 74 57 75 private final EncoderDecoder encoder; 76 private String filename; 58 77 private String subtype; 59 78 private Set<String> usedSections; … … 76 95 this.usedKeys = new HashSet<String>(); 77 96 this.encoder = new TabCrLfEncoderDecoder(true); 97 } 98 99 /** 100 Get the file name that this writer is printing to. 101 @return The file name or null if not known 102 */ 103 public String getFilename() 104 { 105 return filename; 106 } 107 108 /** 109 Set the file name that this writer is printing to. 110 */ 111 public void setFilename(String filename) 112 { 113 this.filename = filename; 78 114 } 79 115
Note: See TracChangeset
for help on using the changeset viewer.