diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..7656d4d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+.project
+.settings
+.classpath
+.gitignore
diff --git a/lib/src/main/java/com/tragicphantom/stdf/Record.java b/lib/src/main/java/com/tragicphantom/stdf/Record.java
index c325b16..8fdf013 100644
--- a/lib/src/main/java/com/tragicphantom/stdf/Record.java
+++ b/lib/src/main/java/com/tragicphantom/stdf/Record.java
@@ -10,60 +10,72 @@
*
* Stdf4j is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
- * along with stdf4j. If not, see .
-**/
+ * along with stdf4j. If not, see .
+ **/
package com.tragicphantom.stdf;
import java.nio.ByteOrder;
-
import java.text.ParseException;
-public class Record{
- private RecordDescriptor desc;
- private int pos;
- private byte [] data;
- private ByteOrder byteOrder;
- private RecordData rd;
+public class Record {
+
+ private RecordDescriptor desc;
+
+ private int pos;
+
+ private byte[] data;
+
+ private ByteOrder byteOrder;
+
+ private RecordData rd;
+
+ public Record(RecordDescriptor desc, int pos, byte[] data, ByteOrder byteOrder) {
+ this.desc = desc;
+ this.pos = pos;
+ this.data = data;
+ this.byteOrder = byteOrder;
+ this.rd = null;
+ }
- public Record(RecordDescriptor desc, int pos,
- byte [] data, ByteOrder byteOrder){
- this.desc = desc;
- this.pos = pos;
- this.data = data;
- this.byteOrder = byteOrder;
- this.rd = null;
- }
+ public Record(RecordDescriptor desc, RecordData rd) {
+ this.desc = desc;
+ this.rd = rd;
+ this.pos = -1;
+ }
- public Record(RecordDescriptor desc, RecordData rd){
- this.desc = desc;
- this.rd = rd;
- this.pos = -1;
- }
+ public String getType() {
+ return this.desc.getType();
+ }
- public String getType(){
- return desc.getType();
- }
+ public int getPosition() {
+ return this.pos;
+ }
- public int getPosition(){
- return pos;
- }
+ public RecordData getData() throws ParseException {
+ if (this.rd == null) {
+ this.rd = this.desc.parse(this.pos, this.data, this.byteOrder);
+ }
+ return this.rd;
+ }
- public RecordData getData() throws ParseException{
- if(rd == null)
- rd = desc.parse(pos, data, byteOrder);
- return rd;
- }
+ public void clean() {
+ if (this.rd != null) {
+ this.rd.clean();
+ }
+ this.rd = null;
+ }
- public String toString(){
- try{
- return getData().toString();
- }
- catch(Exception e){
- return "(null)";
- }
- }
+ @Override
+ public String toString() {
+ try {
+ return getData().toString();
+ }
+ catch (Exception e) {
+ return "(null)";
+ }
+ }
}
diff --git a/lib/src/main/java/com/tragicphantom/stdf/RecordData.java b/lib/src/main/java/com/tragicphantom/stdf/RecordData.java
index 116e955..31a8f28 100644
--- a/lib/src/main/java/com/tragicphantom/stdf/RecordData.java
+++ b/lib/src/main/java/com/tragicphantom/stdf/RecordData.java
@@ -10,136 +10,151 @@
*
* Stdf4j is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
- * along with stdf4j. If not, see .
-**/
+ * along with stdf4j. If not, see .
+ **/
package com.tragicphantom.stdf;
-import java.util.HashMap;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.Calendar;
-import java.util.TimeZone;
-
-public class RecordData{
- private RecordDescriptor desc;
- private Object [] fields;
-
- // TODO: make configurable
- //private static String dateFormat = "%1$tY-%1$tm-%1$tdT%1$tT";
- private static String dateFormat = "%1$ta %1$tb %1$td %1$tT %1$tY";
-
- public RecordData(RecordDescriptor desc, Object [] fields){
- this.desc = desc;
- this.fields = fields;
- }
-
- public String getType(){
- return desc.getType();
- }
-
- public int size(){
- return fields.length;
- }
-
- public boolean hasField(String name){
- return desc.contains(name);
- }
-
- public void setField(int index, Object value){
- fields[index] = value;
- }
-
- public void setField(String name, Object value){
- setField(desc.getIndex(name), value);
- }
-
- public Object getField(String name){
- return getField(desc.getIndex(name));
- }
-
- public Object getField(int index){
- return fields[index];
- }
-
- public HashMap getFields(){
- HashMap values = new HashMap();
- int index = 0;
- for(Field field : desc.getFields())
- values.put(field.getName(), fields[index++]);
- return values;
- }
-
- public String getString(String name){
- int index = desc.getIndex(name);
- Object value = getField(index);
- char type = desc.getFields()[index].getType();
-
- String repr;
- if(value == null)
- repr = "(null)";
- else if(type == 'V' || type == 'k'){
- StringBuilder lb = new StringBuilder();
- for(Object item : (Object[])value){
- if(lb.length() > 0)
- lb.append(", ");
- lb.append(item == null ? "(null)" : item.toString());
- }
- repr = lb.toString();
- }
- else if(value instanceof Double)
- repr = String.format("%f", (Double)value);
- else if(value instanceof Float)
- repr = String.format("%f", (Float)value);
- else if(value instanceof Byte)
- repr = String.format("%x", (Byte)value);
- else if(value instanceof byte[]){
- StringBuilder bb = new StringBuilder("[");
- for(byte b : (byte[])value){
- if(bb.length() > 1)
- bb.append(", ");
- bb.append(Byte.toString(b));
- }
- bb.append("]");
- repr = bb.toString();
- }
- else if((name.endsWith("_T") && !name.equals("TEST_T"))
- || name.equals("MOD_TIM")){
- Calendar cal = Calendar.getInstance();
- //cal.setTimeZone(TimeZone.getTimeZone("GMT"));
- cal.setTimeInMillis((Long)value * 1000L);
- repr = String.format("%1$ta %1$tb %1$td %1$tT %1$tY", cal);
- }
- else
- repr = value.toString();
-
- if(repr.length() == 0)
- repr = "(null)";
-
- return repr;
- }
-
- // this method has been tailored to output similar to libstdf format
- // to help with comparing output of the two libraries
- public String toString(){
- StringBuilder sb = new StringBuilder(getType().toUpperCase());
- sb.append("\n");
-
- // sort fields for easier comparisons
- ArrayList names = new ArrayList(desc.getFieldNames());
- Collections.sort(names);
-
- for(String name : names){
- sb.append(" ")
- .append(name)
- .append(": ")
- .append(getString(name))
- .append("\n");
- }
-
- return sb.toString();
- }
+import java.util.Collections;
+import java.util.HashMap;
+
+public class RecordData {
+
+ private RecordDescriptor desc;
+
+ private Object[] fields;
+
+ // TODO: make configurable
+ //private static String dateFormat = "%1$tY-%1$tm-%1$tdT%1$tT";
+ private static String dateFormat = "%1$ta %1$tb %1$td %1$tT %1$tY";
+
+ public RecordData(RecordDescriptor desc, Object[] fields) {
+ this.desc = desc;
+ this.fields = fields;
+ }
+
+ public String getType() {
+ return this.desc.getType();
+ }
+
+ public int size() {
+ return this.fields.length;
+ }
+
+ public boolean hasField(String name) {
+ return this.desc.contains(name);
+ }
+
+ public void setField(int index, Object value) {
+ this.fields[index] = value;
+ }
+
+ public void setField(String name, Object value) {
+ setField(this.desc.getIndex(name), value);
+ }
+
+ public Object getField(String name) {
+ return getField(this.desc.getIndex(name));
+ }
+
+ public Object getField(int index) {
+ return this.fields[index];
+ }
+
+ public HashMap getFields() {
+ HashMap values = new HashMap();
+ int index = 0;
+ for (Field field : this.desc.getFields()) {
+ values.put(field.getName(), this.fields[index++]);
+ }
+ return values;
+ }
+
+ public void clean() {
+ this.fields = new Object[0];
+ }
+
+ public String getString(String name) {
+ int index = this.desc.getIndex(name);
+ Object value = getField(index);
+ char type = this.desc.getFields()[index].getType();
+
+ String repr;
+ if (value == null) {
+ repr = "(null)";
+ }
+ else if (type == 'V' || type == 'k') {
+ StringBuilder lb = new StringBuilder();
+ for (Object item : (Object[]) value) {
+ if (lb.length() > 0) {
+ lb.append(", ");
+ }
+ lb.append(item == null ? "(null)" : item.toString());
+ }
+ repr = lb.toString();
+ }
+ else if (value instanceof Double) {
+ repr = String.format("%f", (Double) value);
+ }
+ else if (value instanceof Float) {
+ repr = String.format("%f", (Float) value);
+ }
+ else if (value instanceof Byte) {
+ repr = String.format("%x", (Byte) value);
+ }
+ else if (value instanceof byte[]) {
+ StringBuilder bb = new StringBuilder("[");
+ for (byte b : (byte[]) value) {
+ if (bb.length() > 1) {
+ bb.append(", ");
+ }
+ bb.append(Byte.toString(b));
+ }
+ bb.append("]");
+ repr = bb.toString();
+ }
+ else if ((name.endsWith("_T") && !name.equals("TEST_T"))
+ || name.equals("MOD_TIM")) {
+ Calendar cal = Calendar.getInstance();
+ //cal.setTimeZone(TimeZone.getTimeZone("GMT"));
+ cal.setTimeInMillis((Long) value * 1000L);
+ repr = String.format("%1$ta %1$tb %1$td %1$tT %1$tY", cal);
+ }
+ else {
+ repr = value.toString();
+ }
+
+ if (repr.length() == 0) {
+ repr = "(null)";
+ }
+
+ return repr;
+ }
+
+ // this method has been tailored to output similar to libstdf format
+ // to help with comparing output of the two libraries
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder(getType().toUpperCase());
+ sb.append("\n");
+
+ // sort fields for easier comparisons
+ ArrayList names = new ArrayList(this.desc.getFieldNames());
+ Collections.sort(names);
+
+ for (String name : names) {
+ sb.append(" ")
+ .append(name)
+ .append(": ")
+ .append(getString(name))
+ .append("\n");
+ }
+
+ return sb.toString();
+ }
}