Ejemplo n.º 1
0
  /** Increases this text builder capacity. */
  private void increaseCapacity() {
    MemoryArea.getMemoryArea(this)
        .executeInArea(
            new Runnable() {

              public void run() {
                if (_capacity < C1) { // For small capacity, resize.
                  _capacity <<= 1;
                  char[] tmp = new char[_capacity];
                  System.arraycopy(_low, 0, tmp, 0, _length);
                  _low = tmp;
                  _high[0] = tmp;
                } else { // Add a new low block of 1024 elements.
                  int j = _capacity >> B1;
                  if (j >= _high.length) { // Resizes _high.
                    char[][] tmp = new char[_high.length * 2][];
                    System.arraycopy(_high, 0, tmp, 0, _high.length);
                    _high = tmp;
                  }
                  _high[j] = new char[C1];
                  _capacity += C1;
                }
              }
            });
  }
Ejemplo n.º 2
0
  // Resizes prefix mapping  stack.
  private void resizePrefixStack() {
    MemoryArea.getMemoryArea(this)
        .executeInArea(
            new Runnable() {
              public void run() {
                final int oldLength = _prefixes.length;
                final int newLength = oldLength * 2;

                // Resizes prefixes.
                CharArray[] tmp0 = new CharArray[newLength];
                System.arraycopy(_prefixes, 0, tmp0, 0, oldLength);
                _prefixes = tmp0;

                // Resizes namespaces uri.
                CharArray[] tmp1 = new CharArray[newLength];
                System.arraycopy(_namespaces, 0, tmp1, 0, oldLength);
                _namespaces = tmp1;

                // Resizes prefix sets.
                boolean[] tmp2 = new boolean[newLength];
                System.arraycopy(_prefixesWritten, 0, tmp2, 0, oldLength);
                _prefixesWritten = tmp2;

                // Resizes temporary prefix (CharSequence to CharArray conversion).
                CharArray[] tmp3 = new CharArray[newLength];
                System.arraycopy(_prefixesTmp, 0, tmp3, 0, oldLength);
                _prefixesTmp = tmp3;

                // Resizes temporary namespaces (CharSequence to CharArray conversion).
                CharArray[] tmp4 = new CharArray[newLength];
                System.arraycopy(_namespacesTmp, 0, tmp4, 0, oldLength);
                _namespacesTmp = tmp4;
              }
            });
  }
Ejemplo n.º 3
0
  // Used only by XMLStreamWriter (converts CharSequence to CharArray).
  // Null values are not allowed.
  void setPrefix(final CharSequence prefix, CharSequence uri, boolean isWritten) {
    final int index = _namespacesCount[_nesting];
    _prefixesWritten[index] = isWritten;
    final int prefixLength = prefix.length();
    CharArray prefixTmp = _prefixesTmp[index];
    if ((prefixTmp == null) || (prefixTmp.array().length < prefixLength)) {
      MemoryArea.getMemoryArea(this)
          .executeInArea(
              new Runnable() {
                public void run() {
                  _prefixesTmp[index] = new CharArray().setArray(new char[prefixLength + 32], 0, 0);
                }
              });
      prefixTmp = _prefixesTmp[index];
    }
    for (int i = 0; i < prefixLength; i++) {
      prefixTmp.array()[i] = prefix.charAt(i);
    }
    prefixTmp.setArray(prefixTmp.array(), 0, prefixLength);

    final int uriLength = uri.length();
    CharArray namespaceTmp = _namespacesTmp[index];
    if ((namespaceTmp == null) || (namespaceTmp.array().length < uriLength)) {
      MemoryArea.getMemoryArea(this)
          .executeInArea(
              new Runnable() {
                public void run() {
                  _namespacesTmp[index] = new CharArray().setArray(new char[uriLength + 32], 0, 0);
                }
              });
      namespaceTmp = _namespacesTmp[index];
    }
    for (int i = 0; i < uriLength; i++) {
      namespaceTmp.array()[i] = uri.charAt(i);
    }
    namespaceTmp.setArray(namespaceTmp.array(), 0, uriLength);

    // Sets the prefix using CharArray instances.
    setPrefix(prefixTmp, namespaceTmp);
  }
Ejemplo n.º 4
0
  private void resizeNamespacesCount() {
    MemoryArea.getMemoryArea(this)
        .executeInArea(
            new Runnable() {
              public void run() {
                final int oldLength = _namespacesCount.length;
                final int newLength = oldLength * 2;

                // Resizes namespaces counts.
                int[] tmp = new int[newLength];
                System.arraycopy(_namespacesCount, 0, tmp, 0, oldLength);
                _namespacesCount = tmp;
              }
            });
  }