ctf: Hide internal functionalities of StringDefinition.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / ctf / core / event / types / StringDefinition.java
index 6601579f8b97f3777d87a2f61b83dceb6a1a807c..ff27e849be33c820dd96bf08857d8bced2fdf2b4 100644 (file)
@@ -13,6 +13,7 @@
 package org.eclipse.linuxtools.ctf.core.event.types;
 
 import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 
 /**
  * A CTF string definition (similar to a C null-terminated byte array).
@@ -31,9 +32,9 @@ public class StringDefinition extends Definition {
     // Attributes
     // ------------------------------------------------------------------------
 
-    private StringDeclaration declaration;
+    private StringDeclaration fDeclaration;
 
-    private StringBuilder string;
+    private String fString;
 
     // ------------------------------------------------------------------------
     // Constructors
@@ -41,17 +42,21 @@ public class StringDefinition extends Definition {
 
     /**
      * Constructor
-     * @param declaration the parent declaration
-     * @param definitionScope the parent scope
-     * @param fieldName the field name
+     *
+     * @param declaration
+     *            the parent declaration
+     * @param definitionScope
+     *            the parent scope
+     * @param fieldName
+     *            the field name
      */
     public StringDefinition(StringDeclaration declaration,
             IDefinitionScope definitionScope, String fieldName) {
         super(definitionScope, fieldName);
 
-        this.declaration = declaration;
+        fDeclaration = declaration;
 
-        string = new StringBuilder();
+        fString = ""; //$NON-NLS-1$
     }
 
     // ------------------------------------------------------------------------
@@ -60,39 +65,35 @@ public class StringDefinition extends Definition {
 
     @Override
     public StringDeclaration getDeclaration() {
-        return declaration;
+        return fDeclaration;
     }
 
     /**
      * Sets the string declaration
-     * @param declaration the declaration
+     *
+     * @param declaration
+     *            the declaration
      */
     public void setDeclaration(StringDeclaration declaration) {
-        this.declaration = declaration;
+        fDeclaration = declaration;
     }
 
     /**
-     * Gets the string
-     * @return the stringbuilder
-     */
-    public StringBuilder getString() {
-        return string;
-    }
-
-    /**
-     * Sets a stringbuilder for the definition
-     * @param string the stringbuilder
+     * Gets the string (value)
+     *
+     * @return the string
      */
-    public void setString(StringBuilder string) {
-        this.string = string;
+    public String getValue() {
+        return fString;
     }
 
     /**
-     * Gets the string (value)
-     * @return the string
+     * Sets the string (value)
+     *
+     * @param str the string
      */
-    public String getValue() {
-        return string.toString();
+    public void setValue(String str) {
+        fString = str;
     }
 
     // ------------------------------------------------------------------------
@@ -100,19 +101,17 @@ public class StringDefinition extends Definition {
     // ------------------------------------------------------------------------
 
     @Override
-    public void read(BitBuffer input) {
+    public void read(BitBuffer input) throws CTFReaderException {
         /* Offset the buffer position wrt the current alignment */
-        int align = (int) declaration.getAlignment();
-        long pos = input.position() + ((align - (input.position() % align)) % align);
-        input.position(pos);
-
-        string.setLength(0);
+        alignRead(input, fDeclaration);
 
-        char c = (char) input.getInt(8, false);
+        StringBuilder sb = new StringBuilder();
+        char c = (char) input.get(8, false);
         while (c != 0) {
-            string.append(c);
-            c = (char) input.getInt(8, false);
+            sb.append(c);
+            c = (char) input.get(8, false);
         }
+        fString = sb.toString();
     }
 
     @Override
This page took 0.051681 seconds and 5 git commands to generate.