public String contentToString() { StringBuffer sb = new StringBuffer(); sb.append(name + " = \n"); if (getM() * getN() == 1) { for (String key : keys) { sb.append("\t" + key + " : " + getField(key) + "\n"); } } else { sb.append("\n"); sb.append(getM() + "x" + getN()); sb.append(" struct array with fields: \n"); for (String key : keys) { sb.append("\t" + key + "\n"); } } return sb.toString(); }
/** * Sets field for current structure * * @param name - name of the field * @param value - <code>MLArray</code> field value */ public void setField(String name, MLArray value) { setField(name, value, currentIndex); }
/** * Gets a value of the field described by name from current struct * in struct array or null if the field doesn't exist. * * @param name * @return */ public MLArray getField(String name) { return getField(name, currentIndex); }
/** * Dumps field names to byte array. Field names are written as Zero End Strings * * @return */ public byte[] getKeySetToByteArray() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); char[] buffer = new char[getMaxFieldLenth()]; try { for (String s : keys) { Arrays.fill(buffer, (char) 0); System.arraycopy(s.toCharArray(), 0, buffer, 0, s.length()); dos.writeBytes(new String(buffer)); } } catch (IOException e) { System.err.println("Could not write Structure key set to byte array: " + e); return new byte[0]; } return baos.toByteArray(); }
public String contentToString() { StringBuffer sb = new StringBuffer(); sb.append(name + " = \n"); if (getM() * getN() == 1) { for (String key : keys) { sb.append("\t" + key + " : " + getField(key) + "\n"); } } else { sb.append("\n"); sb.append(getM() + "x" + getN()); sb.append(" struct array with fields: \n"); for (String key : keys) { sb.append("\t" + key + "\n"); } } return sb.toString(); }
/** * Sets field for current structure * * @param name - name of the field * @param value - <code>MLArray</code> field value */ public void setField(String name, MLArray value) { setField(name, value, currentIndex); }
/** * Gets a value of the field described by name from current struct * in struct array or null if the field doesn't exist. * * @param name * @return */ public MLArray getField(String name) { return getField(name, currentIndex); }
/** * Dumps field names to byte array. Field names are written as Zero End Strings * * @return */ public byte[] getKeySetToByteArray() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); char[] buffer = new char[getMaxFieldLenth()]; try { for (String s : keys) { Arrays.fill(buffer, (char) 0); System.arraycopy(s.toCharArray(), 0, buffer, 0, s.length()); dos.writeBytes(new String(buffer)); } } catch (IOException e) { System.err.println("Could not write Structure key set to byte array: " + e); return new byte[0]; } return baos.toByteArray(); }