1 2 17 18 19 package org.apache.poi.hdf.generator; 20 21 import org.apache.poi.generator.FieldIterator; 22 import org.apache.poi.generator.RecordUtil; 23 24 27 public class HDFFieldIterator extends FieldIterator 28 { 29 30 public HDFFieldIterator() 31 { 32 } 33 34 public String fillDecoder(String size, String type) 35 { 36 37 String result = ""; 38 39 if (type.equals("short[]")) 40 result = "LittleEndian.getSimpleShortArray(data, 0x" + Integer.toHexString(offset) + " + offset," + size + ")"; 41 else if (type.equals("byte[]")) 42 result = "LittleEndian.getByteArray(data, 0x" + Integer.toHexString(offset) + " + offset," + size + ")"; 43 else if (type.equals("BorderCode")) 44 result = "new BorderCode(data, 0x" + Integer.toHexString(offset) + " + offset)"; 45 else if (type.equals("DateAndTime")) 46 result = "new DateAndTime(data, 0x" + Integer.toHexString(offset) + " + offset)"; 47 else if (size.equals("2")) 48 result = "LittleEndian.getShort(data, 0x" + Integer.toHexString(offset) + " + offset)"; 49 else if (size.equals("4")) 50 result = "LittleEndian.getInt(data, 0x" + Integer.toHexString(offset) + " + offset)"; 51 else if (size.equals("1")) 52 result = "data[ 0x" + Integer.toHexString(offset) + " + offset ]"; 53 else if (type.equals("double")) 54 result = "LittleEndian.getDouble(data, 0x" + Integer.toHexString(offset) + " + offset)"; 55 56 try 57 { 58 offset += Integer.parseInt(size); 59 } 60 catch (NumberFormatException ignore) 61 { 62 } 63 return result; 64 } 65 66 public String serialiseEncoder( int fieldNumber, String fieldName, String size, String type) 67 { 68 String javaFieldName = RecordUtil.getFieldName(fieldNumber,fieldName,0); 70 71 String result = ""; 72 73 74 if (type.equals("short[]")) 75 result = "LittleEndian.putShortArray(data, 0x" + Integer.toHexString(offset) + " + offset, " + javaFieldName + ");"; 76 else if (type.equals("byte[]")) 77 result = "System.arraycopy(" + javaFieldName + ", 0, data, 0x" + Integer.toHexString(offset) + " + offset, " + javaFieldName + ".length);"; 78 else if (type.equals("BorderCode")) 79 result = javaFieldName + ".serialize(data, 0x" + Integer.toHexString(offset) + " + offset);"; 80 else if (type.equals("DateAndTime")) 81 result = javaFieldName + ".serialize(data, 0x" + Integer.toHexString(offset) + " + offset);"; 82 else if (size.equals("2")) 83 result = "LittleEndian.putShort(data, 0x" + Integer.toHexString(offset) + " + offset, (short)" + javaFieldName + ");"; 84 else if (size.equals("4")) 85 result = "LittleEndian.putInt(data, 0x" + Integer.toHexString(offset) + " + offset, " + javaFieldName + ");"; 86 else if (size.equals("1")) 87 result = "data[ 0x" + Integer.toHexString(offset) + " + offset] = " + javaFieldName + ";"; 88 else if (type.equals("double")) 89 result = "LittleEndian.putDouble(data, 0x" + Integer.toHexString(offset) + " + offset, " + javaFieldName + ");"; 90 91 try 92 { 93 offset += Integer.parseInt(size); 94 } 95 catch (NumberFormatException ignore) 96 { 97 } 98 return result; 99 100 } 101 102 } 103 | Popular Tags |