com.fasterxml.jackson.databind.util.TokenBuffer.java Source code

Java tutorial

Introduction

Here is the source code for com.fasterxml.jackson.databind.util.TokenBuffer.java

Source

  package com.fasterxml.jackson.databind.util;

  import com.fasterxml.jackson.core.Base64Variant;
  import com.fasterxml.jackson.core.JsonGenerationException;
  import com.fasterxml.jackson.core.JsonGenerator;
  import com.fasterxml.jackson.core.JsonLocation;
  import com.fasterxml.jackson.core.JsonParser;
  import com.fasterxml.jackson.core.JsonParser.Feature;
  import com.fasterxml.jackson.core.JsonParser.NumberType;
  import com.fasterxml.jackson.core.JsonToken;
  import com.fasterxml.jackson.core.ObjectCodec;
  import com.fasterxml.jackson.core.SerializableString;
  import com.fasterxml.jackson.core.base.ParserMinimalBase;
  import com.fasterxml.jackson.core.json.JsonReadContext;
  import com.fasterxml.jackson.core.json.JsonWriteContext;
  import com.fasterxml.jackson.core.util.ByteArrayBuilder;
  import java.io.IOException;
  import java.math.BigDecimal;
  import java.math.BigInteger;

  public class TokenBuffer extends JsonGenerator {
      protected static final int DEFAULT_PARSER_FEATURES = JsonParser.Feature.collectDefaults();
      protected int _appendOffset;
      protected boolean _closed;
      protected Segment _first;
      protected int _generatorFeatures;
      protected Segment _last;
      protected ObjectCodec _objectCodec;
      protected JsonWriteContext _writeContext;

      public TokenBuffer(ObjectCodec paramObjectCodec) {
          this._objectCodec = paramObjectCodec;
          this._generatorFeatures = DEFAULT_PARSER_FEATURES;
          this._writeContext = JsonWriteContext.createRootContext();
          Segment localSegment = new Segment();
          this._last = localSegment;
          this._first = localSegment;
          this._appendOffset = 0;
      }

      protected final void _append(JsonToken paramJsonToken) {
          Segment localSegment = this._last.append(this._appendOffset, paramJsonToken);
          if (localSegment == null) {
              this._appendOffset = (1 + this._appendOffset);
              return;
          }
          this._last = localSegment;
          this._appendOffset = 1;
      }

      protected final void _append(JsonToken paramJsonToken, Object paramObject) {
          Segment localSegment = this._last.append(this._appendOffset, paramJsonToken, paramObject);
          if (localSegment == null) {
              this._appendOffset = (1 + this._appendOffset);
              return;
          }
          this._last = localSegment;
          this._appendOffset = 1;
      }

      protected void _reportUnsupportedOperation() {
          throw new UnsupportedOperationException("Called operation not supported for TokenBuffer");
      }

      public TokenBuffer append(TokenBuffer paramTokenBuffer) {
          JsonParser localJsonParser = paramTokenBuffer.asParser();
          while (localJsonParser.nextToken() != null)
              copyCurrentEvent(localJsonParser);
          return this;
      }

      public JsonParser asParser() {
          return asParser(this._objectCodec);
      }

      public JsonParser asParser(JsonParser paramJsonParser) {
          Parser localParser = new Parser(this._first, paramJsonParser.getCodec());
          localParser.setLocation(paramJsonParser.getTokenLocation());
          return localParser;
      }

      public JsonParser asParser(ObjectCodec paramObjectCodec) {
          return new Parser(this._first, paramObjectCodec);
      }

      public void close() {
          this._closed = true;
      }

public void copyCurrentEvent(JsonParser paramJsonParser)
{
  switch (1.$SwitchMap$com$fasterxml$jackson$core$JsonToken[paramJsonParser.getCurrentToken().ordinal()])
  {
  default:
    throw new RuntimeException("Internal error: should never end up through this code path");
  case 1:
    writeStartObject();
    return;
  case 2:
    writeEndObject();
    return;
  case 3:
    writeStartArray();
    return;
  case 4:
    writeEndArray();
    return;
  case 5:
    writeFieldName(paramJsonParser.getCurrentName());
    return;
  case 6:
    if (paramJsonParser.hasTextCharacters())
    {
      writeString(paramJsonParser.getTextCharacters(), paramJsonParser.getTextOffset(), paramJsonParser.getTextLength());
      return;
    }
    writeString(paramJsonParser.getText());
    return;
  case 7:
    switch (1.$SwitchMap$com$fasterxml$jackson$core$JsonParser$NumberType[paramJsonParser.getNumberType().ordinal()])
    {
    default:
      writeNumber(paramJsonParser.getLongValue());
      return;
    case 1:
      writeNumber(paramJsonParser.getIntValue());
      return;
    case 2:
    }
    writeNumber(paramJsonParser.getBigIntegerValue());
    return;
  case 8:
    switch (1.$SwitchMap$com$fasterxml$jackson$core$JsonParser$NumberType[paramJsonParser.getNumberType().ordinal()])
    {
    default:
      writeNumber(paramJsonParser.getDoubleValue());
      return;
    case 3:
      writeNumber(paramJsonParser.getDecimalValue());
      return;
    case 4:
    }
    writeNumber(paramJsonParser.getFloatValue());
    return;
  case 9:
    writeBoolean(true);
    return;
  case 10:
    writeBoolean(false);
    return;
  case 11:
    writeNull();
    return;
  case 12:
  }
  writeObject(paramJsonParser.getEmbeddedObject());
}

public void copyCurrentStructure(JsonParser paramJsonParser)
{
  JsonToken localJsonToken = paramJsonParser.getCurrentToken();
  if (localJsonToken == JsonToken.FIELD_NAME)
  {
    writeFieldName(paramJsonParser.getCurrentName());
    localJsonToken = paramJsonParser.nextToken();
  }
  switch (1.$SwitchMap$com$fasterxml$jackson$core$JsonToken[localJsonToken.ordinal()])
  {
  case 2:
  default:
    copyCurrentEvent(paramJsonParser);
    return;
  case 3:
    writeStartArray();
    while (paramJsonParser.nextToken() != JsonToken.END_ARRAY)
      copyCurrentStructure(paramJsonParser);
    writeEndArray();
    return;
  case 1:
  }
  writeStartObject();
  while (paramJsonParser.nextToken() != JsonToken.END_OBJECT)
    copyCurrentStructure(paramJsonParser);
  writeEndObject();
}

      public void flush() {
      }

public void serialize(JsonGenerator paramJsonGenerator)
{
  Segment localSegment1 = this._first;
  int i = -1;
  Object localObject1 = localSegment1;
  int j = i + 1;
  label34: int k;
  Object localObject2;
  if (j >= 16)
  {
    Segment localSegment2 = ((Segment)localObject1).next();
    if (localSegment2 == null)
      return;
    k = 0;
    localObject2 = localSegment2;
  }
  while (true)
  {
    JsonToken localJsonToken = ((Segment)localObject2).type(k);
    if (localJsonToken == null)
      break label34;
    switch (1.$SwitchMap$com$fasterxml$jackson$core$JsonToken[localJsonToken.ordinal()])
    {
    default:
      throw new RuntimeException("Internal error: should never end up through this code path");
    case 1:
      paramJsonGenerator.writeStartObject();
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
    case 7:
    case 8:
    case 9:
    case 10:
    case 11:
    case 12:
    }
    while (true)
    {
      i = k;
      localObject1 = localObject2;
      break;
      paramJsonGenerator.writeEndObject();
      continue;
      paramJsonGenerator.writeStartArray();
      continue;
      paramJsonGenerator.writeEndArray();
      continue;
      Object localObject5 = ((Segment)localObject2).get(k);
      if ((localObject5 instanceof SerializableString))
      {
        paramJsonGenerator.writeFieldName((SerializableString)localObject5);
      }
      else
      {
        paramJsonGenerator.writeFieldName((String)localObject5);
        continue;
        Object localObject4 = ((Segment)localObject2).get(k);
        if ((localObject4 instanceof SerializableString))
        {
          paramJsonGenerator.writeString((SerializableString)localObject4);
        }
        else
        {
          paramJsonGenerator.writeString((String)localObject4);
          continue;
          Number localNumber = (Number)((Segment)localObject2).get(k);
          if ((localNumber instanceof BigInteger))
          {
            paramJsonGenerator.writeNumber((BigInteger)localNumber);
          }
          else if ((localNumber instanceof Long))
          {
            paramJsonGenerator.writeNumber(localNumber.longValue());
          }
          else
          {
            paramJsonGenerator.writeNumber(localNumber.intValue());
            continue;
            Object localObject3 = ((Segment)localObject2).get(k);
            if ((localObject3 instanceof BigDecimal))
            {
              paramJsonGenerator.writeNumber((BigDecimal)localObject3);
            }
            else if ((localObject3 instanceof Float))
            {
              paramJsonGenerator.writeNumber(((Float)localObject3).floatValue());
            }
            else if ((localObject3 instanceof Double))
            {
              paramJsonGenerator.writeNumber(((Double)localObject3).doubleValue());
            }
            else if (localObject3 == null)
            {
              paramJsonGenerator.writeNull();
            }
            else if ((localObject3 instanceof String))
            {
              paramJsonGenerator.writeNumber((String)localObject3);
            }
            else
            {
              throw new JsonGenerationException("Unrecognized value type for VALUE_NUMBER_FLOAT: " + localObject3.getClass().getName() + ", can not serialize");
              paramJsonGenerator.writeBoolean(true);
              continue;
              paramJsonGenerator.writeBoolean(false);
              continue;
              paramJsonGenerator.writeNull();
              continue;
              paramJsonGenerator.writeObject(((Segment)localObject2).get(k));
            }
          }
        }
      }
    }
    localObject2 = localObject1;
    k = j;
  }
}

      public String toString() {
          StringBuilder localStringBuilder = new StringBuilder();
          localStringBuilder.append("[TokenBuffer: ");
          JsonParser localJsonParser = asParser();
          int i = 0;
          try {
              while (true) {
                  JsonToken localJsonToken = localJsonParser.nextToken();
                  if (localJsonToken == null) {
                      if (i >= 100)
                          localStringBuilder.append(" ... (truncated ").append(i - 100).append(" entries)");
                      localStringBuilder.append(']');
                      return localStringBuilder.toString();
                  }
                  if (i < 100) {
                      if (i > 0)
                          localStringBuilder.append(", ");
                      localStringBuilder.append(localJsonToken.toString());
                      if (localJsonToken == JsonToken.FIELD_NAME) {
                          localStringBuilder.append('(');
                          localStringBuilder.append(localJsonParser.getCurrentName());
                          localStringBuilder.append(')');
                      }
                  }
                  i++;
              }
          } catch (IOException localIOException) {
              throw new IllegalStateException(localIOException);
          }
      }

      public JsonGenerator useDefaultPrettyPrinter() {
          return this;
      }

      public void writeBinary(Base64Variant paramBase64Variant, byte[] paramArrayOfByte, int paramInt1,
              int paramInt2) {
          byte[] arrayOfByte = new byte[paramInt2];
          System.arraycopy(paramArrayOfByte, paramInt1, arrayOfByte, 0, paramInt2);
          writeObject(arrayOfByte);
      }

      public void writeBoolean(boolean paramBoolean) {
          if (paramBoolean)
              ;
          for (JsonToken localJsonToken = JsonToken.VALUE_TRUE;; localJsonToken = JsonToken.VALUE_FALSE) {
              _append(localJsonToken);
              return;
          }
      }

      public final void writeEndArray() {
          _append(JsonToken.END_ARRAY);
          JsonWriteContext localJsonWriteContext = this._writeContext.getParent();
          if (localJsonWriteContext != null)
              this._writeContext = localJsonWriteContext;
      }

      public final void writeEndObject() {
          _append(JsonToken.END_OBJECT);
          JsonWriteContext localJsonWriteContext = this._writeContext.getParent();
          if (localJsonWriteContext != null)
              this._writeContext = localJsonWriteContext;
      }

      public void writeFieldName(SerializableString paramSerializableString) {
          _append(JsonToken.FIELD_NAME, paramSerializableString);
          this._writeContext.writeFieldName(paramSerializableString.getValue());
      }

      public final void writeFieldName(String paramString) {
          _append(JsonToken.FIELD_NAME, paramString);
          this._writeContext.writeFieldName(paramString);
      }

      public void writeNull() {
          _append(JsonToken.VALUE_NULL);
      }

      public void writeNumber(double paramDouble) {
          _append(JsonToken.VALUE_NUMBER_FLOAT, Double.valueOf(paramDouble));
      }

      public void writeNumber(float paramFloat) {
          _append(JsonToken.VALUE_NUMBER_FLOAT, Float.valueOf(paramFloat));
      }

      public void writeNumber(int paramInt) {
          _append(JsonToken.VALUE_NUMBER_INT, Integer.valueOf(paramInt));
      }

      public void writeNumber(long paramLong) {
          _append(JsonToken.VALUE_NUMBER_INT, Long.valueOf(paramLong));
      }

      public void writeNumber(String paramString) {
          _append(JsonToken.VALUE_NUMBER_FLOAT, paramString);
      }

      public void writeNumber(BigDecimal paramBigDecimal) {
          if (paramBigDecimal == null) {
              writeNull();
              return;
          }
          _append(JsonToken.VALUE_NUMBER_FLOAT, paramBigDecimal);
      }

      public void writeNumber(BigInteger paramBigInteger) {
          if (paramBigInteger == null) {
              writeNull();
              return;
          }
          _append(JsonToken.VALUE_NUMBER_INT, paramBigInteger);
      }

      public void writeObject(Object paramObject) {
          _append(JsonToken.VALUE_EMBEDDED_OBJECT, paramObject);
      }

      public void writeRaw(char paramChar) {
          _reportUnsupportedOperation();
      }

      public void writeRaw(SerializableString paramSerializableString) {
          _reportUnsupportedOperation();
      }

      public void writeRaw(String paramString) {
          _reportUnsupportedOperation();
      }

      public void writeRaw(char[] paramArrayOfChar, int paramInt1, int paramInt2) {
          _reportUnsupportedOperation();
      }

      public void writeRawValue(String paramString) {
          _reportUnsupportedOperation();
      }

      public final void writeStartArray() {
          _append(JsonToken.START_ARRAY);
          this._writeContext = this._writeContext.createChildArrayContext();
      }

      public final void writeStartObject() {
          _append(JsonToken.START_OBJECT);
          this._writeContext = this._writeContext.createChildObjectContext();
      }

      public void writeString(SerializableString paramSerializableString) {
          if (paramSerializableString == null) {
              writeNull();
              return;
          }
          _append(JsonToken.VALUE_STRING, paramSerializableString);
      }

      public void writeString(String paramString) {
          if (paramString == null) {
              writeNull();
              return;
          }
          _append(JsonToken.VALUE_STRING, paramString);
      }

      public void writeString(char[] paramArrayOfChar, int paramInt1, int paramInt2) {
          writeString(new String(paramArrayOfChar, paramInt1, paramInt2));
      }

      protected static final class Parser extends ParserMinimalBase {
          protected transient ByteArrayBuilder _byteBuilder;
          protected boolean _closed;
          protected ObjectCodec _codec;
          protected JsonLocation _location = null;
          protected JsonReadContext _parsingContext;
          protected TokenBuffer.Segment _segment;
          protected int _segmentPtr;

          public Parser(TokenBuffer.Segment paramSegment, ObjectCodec paramObjectCodec) {
              super();
              this._segment = paramSegment;
              this._segmentPtr = -1;
              this._codec = paramObjectCodec;
              this._parsingContext = JsonReadContext.createRootContext(-1, -1);
          }

          protected final void _checkIsNumber() {
              if ((this._currToken == null) || (!this._currToken.isNumeric()))
                  throw _constructError(
                          "Current token (" + this._currToken + ") not numeric, can not use numeric value accessors");
          }

          protected final Object _currentObject() {
              return this._segment.get(this._segmentPtr);
          }

          protected void _handleEOF() {
              _throwInternal();
          }

          public void close() {
              if (!this._closed)
                  this._closed = true;
          }

  public BigInteger getBigIntegerValue()
  {
    Number localNumber = getNumberValue();
    if ((localNumber instanceof BigInteger))
      return (BigInteger)localNumber;
    switch (TokenBuffer.1.$SwitchMap$com$fasterxml$jackson$core$JsonParser$NumberType[getNumberType().ordinal()])
    {
    default:
      return BigInteger.valueOf(localNumber.longValue());
    case 3:
    }
    return ((BigDecimal)localNumber).toBigInteger();
  }

          public byte[] getBinaryValue(Base64Variant paramBase64Variant) {
              if (this._currToken == JsonToken.VALUE_EMBEDDED_OBJECT) {
                  Object localObject = _currentObject();
                  if ((localObject instanceof byte[]))
                      return (byte[]) localObject;
              }
              if (this._currToken != JsonToken.VALUE_STRING)
                  throw _constructError("Current token (" + this._currToken
                          + ") not VALUE_STRING (or VALUE_EMBEDDED_OBJECT with byte[]), can not access as binary");
              String str = getText();
              if (str == null)
                  return null;
              ByteArrayBuilder localByteArrayBuilder = this._byteBuilder;
              if (localByteArrayBuilder == null) {
                  localByteArrayBuilder = new ByteArrayBuilder(100);
                  this._byteBuilder = localByteArrayBuilder;
              }
              while (true) {
                  _decodeBase64(str, localByteArrayBuilder, paramBase64Variant);
                  return localByteArrayBuilder.toByteArray();
                  this._byteBuilder.reset();
              }
          }

          public ObjectCodec getCodec() {
              return this._codec;
          }

          public JsonLocation getCurrentLocation() {
              if (this._location == null)
                  return JsonLocation.NA;
              return this._location;
          }

          public String getCurrentName() {
              return this._parsingContext.getCurrentName();
          }

  public BigDecimal getDecimalValue()
  {
    Number localNumber = getNumberValue();
    if ((localNumber instanceof BigDecimal))
      return (BigDecimal)localNumber;
    switch (TokenBuffer.1.$SwitchMap$com$fasterxml$jackson$core$JsonParser$NumberType[getNumberType().ordinal()])
    {
    case 3:
    case 4:
    default:
      return BigDecimal.valueOf(localNumber.doubleValue());
    case 1:
    case 5:
      return BigDecimal.valueOf(localNumber.longValue());
    case 2:
    }
    return new BigDecimal((BigInteger)localNumber);
  }

          public double getDoubleValue() {
              return getNumberValue().doubleValue();
          }

          public Object getEmbeddedObject() {
              if (this._currToken == JsonToken.VALUE_EMBEDDED_OBJECT)
                  return _currentObject();
              return null;
          }

          public float getFloatValue() {
              return getNumberValue().floatValue();
          }

          public int getIntValue() {
              if (this._currToken == JsonToken.VALUE_NUMBER_INT)
                  return ((Number) _currentObject()).intValue();
              return getNumberValue().intValue();
          }

          public long getLongValue() {
              return getNumberValue().longValue();
          }

          public JsonParser.NumberType getNumberType() {
              Number localNumber = getNumberValue();
              if ((localNumber instanceof Integer))
                  return JsonParser.NumberType.INT;
              if ((localNumber instanceof Long))
                  return JsonParser.NumberType.LONG;
              if ((localNumber instanceof Double))
                  return JsonParser.NumberType.DOUBLE;
              if ((localNumber instanceof BigDecimal))
                  return JsonParser.NumberType.BIG_DECIMAL;
              if ((localNumber instanceof Float))
                  return JsonParser.NumberType.FLOAT;
              if ((localNumber instanceof BigInteger))
                  return JsonParser.NumberType.BIG_INTEGER;
              return null;
          }

          public final Number getNumberValue() {
              _checkIsNumber();
              return (Number) _currentObject();
          }

  public String getText()
  {
    Object localObject1;
    String str2;
    if ((this._currToken == JsonToken.VALUE_STRING) || (this._currToken == JsonToken.FIELD_NAME))
    {
      localObject1 = _currentObject();
      if ((localObject1 instanceof String))
        str2 = (String)localObject1;
    }
    Object localObject2;
    do
    {
      JsonToken localJsonToken;
      do
      {
        return str2;
        if (localObject1 == null);
        for (String str1 = null; ; str1 = localObject1.toString())
          return str1;
        localJsonToken = this._currToken;
        str2 = null;
      }
      while (localJsonToken == null);
      switch (TokenBuffer.1.$SwitchMap$com$fasterxml$jackson$core$JsonToken[this._currToken.ordinal()])
      {
      default:
        return this._currToken.asString();
      case 7:
      case 8:
      }
      localObject2 = _currentObject();
      str2 = null;
    }
    while (localObject2 == null);
    return localObject2.toString();
  }

          public char[] getTextCharacters() {
              String str = getText();
              if (str == null)
                  return null;
              return str.toCharArray();
          }

          public int getTextLength() {
              String str = getText();
              if (str == null)
                  return 0;
              return str.length();
          }

          public int getTextOffset() {
              return 0;
          }

          public JsonLocation getTokenLocation() {
              return getCurrentLocation();
          }

          public boolean hasTextCharacters() {
              return false;
          }

          public JsonToken nextToken() {
              if ((this._closed) || (this._segment == null))
                  ;
              do {
                  return null;
                  int i = 1 + this._segmentPtr;
                  this._segmentPtr = i;
                  if (i < 16)
                      break;
                  this._segmentPtr = 0;
                  this._segment = this._segment.next();
              } while (this._segment == null);
              this._currToken = this._segment.type(this._segmentPtr);
              Object localObject;
              String str;
              if (this._currToken == JsonToken.FIELD_NAME) {
                  localObject = _currentObject();
                  if ((localObject instanceof String)) {
                      str = (String) localObject;
                      this._parsingContext.setCurrentName(str);
                  }
              }
              while (true) {
                  return this._currToken;
                  str = localObject.toString();
                  break;
                  if (this._currToken == JsonToken.START_OBJECT) {
                      this._parsingContext = this._parsingContext.createChildObjectContext(-1, -1);
                  } else if (this._currToken == JsonToken.START_ARRAY) {
                      this._parsingContext = this._parsingContext.createChildArrayContext(-1, -1);
                  } else if ((this._currToken == JsonToken.END_OBJECT) || (this._currToken == JsonToken.END_ARRAY)) {
                      this._parsingContext = this._parsingContext.getParent();
                      if (this._parsingContext == null)
                          this._parsingContext = JsonReadContext.createRootContext(-1, -1);
                  }
              }
          }

          public void setLocation(JsonLocation paramJsonLocation) {
              this._location = paramJsonLocation;
          }
      }

      protected static final class Segment {
          private static final JsonToken[] TOKEN_TYPES_BY_INDEX = new JsonToken[16];
          protected Segment _next;
          protected long _tokenTypes;
          protected final Object[] _tokens = new Object[16];

          static {
              JsonToken[] arrayOfJsonToken = JsonToken.values();
              System.arraycopy(arrayOfJsonToken, 1, TOKEN_TYPES_BY_INDEX, 1,
                      Math.min(15, -1 + arrayOfJsonToken.length));
          }

          public Segment append(int paramInt, JsonToken paramJsonToken) {
              if (paramInt < 16) {
                  set(paramInt, paramJsonToken);
                  return null;
              }
              this._next = new Segment();
              this._next.set(0, paramJsonToken);
              return this._next;
          }

          public Segment append(int paramInt, JsonToken paramJsonToken, Object paramObject) {
              if (paramInt < 16) {
                  set(paramInt, paramJsonToken, paramObject);
                  return null;
              }
              this._next = new Segment();
              this._next.set(0, paramJsonToken, paramObject);
              return this._next;
          }

          public Object get(int paramInt) {
              return this._tokens[paramInt];
          }

          public Segment next() {
              return this._next;
          }

          public void set(int paramInt, JsonToken paramJsonToken) {
              long l = paramJsonToken.ordinal();
              if (paramInt > 0)
                  l <<= paramInt << 2;
              this._tokenTypes = (l | this._tokenTypes);
          }

          public void set(int paramInt, JsonToken paramJsonToken, Object paramObject) {
              this._tokens[paramInt] = paramObject;
              long l = paramJsonToken.ordinal();
              if (paramInt > 0)
                  l <<= paramInt << 2;
              this._tokenTypes = (l | this._tokenTypes);
          }

          public JsonToken type(int paramInt) {
              long l = this._tokenTypes;
              if (paramInt > 0)
                  l >>= paramInt << 2;
              int i = 0xF & (int) l;
              return TOKEN_TYPES_BY_INDEX[i];
          }
      }
  }

  /* Location:           /Users/dantheman/src/fffffffffattttt/basis/classes_dex2jar.jar
   * Qualified Name:     com.fasterxml.jackson.databind.util.TokenBuffer
   * JD-Core Version:    0.6.2
   */