Exemplo n.º 1
0
 private int _appendByteEscape(int paramInt1, int paramInt2, ByteArrayBuilder paramByteArrayBuilder, int paramInt3)
 {
   paramByteArrayBuilder.setCurrentSegmentLength(paramInt3);
   paramByteArrayBuilder.append(92);
   if (paramInt2 < 0)
   {
     paramByteArrayBuilder.append(117);
     if (paramInt1 > 255)
     {
       int i = paramInt1 >> 8;
       paramByteArrayBuilder.append(HEX_BYTES[(i >> 4)]);
       paramByteArrayBuilder.append(HEX_BYTES[(i & 0xF)]);
       paramInt1 &= 255;
       paramByteArrayBuilder.append(HEX_BYTES[(paramInt1 >> 4)]);
       paramByteArrayBuilder.append(HEX_BYTES[(paramInt1 & 0xF)]);
     }
   }
   while (true)
   {
     return paramByteArrayBuilder.getCurrentSegmentLength();
     paramByteArrayBuilder.append(48);
     paramByteArrayBuilder.append(48);
     break;
     paramByteArrayBuilder.append((byte)paramInt2);
   }
 }
Exemplo n.º 2
0
 public void appendTwoBytes(int b16) {
   if (this._currBlockPtr + 1 < this._currBlock.length) {
     byte[] bArr = this._currBlock;
     int i = this._currBlockPtr;
     this._currBlockPtr = i + 1;
     bArr[i] = (byte) (b16 >> 8);
     bArr = this._currBlock;
     i = this._currBlockPtr;
     this._currBlockPtr = i + 1;
     bArr[i] = (byte) b16;
     return;
   }
   append(b16 >> 8);
   append(b16);
 }
Exemplo n.º 3
0
 public void appendThreeBytes(int b24) {
   if (this._currBlockPtr + 2 < this._currBlock.length) {
     byte[] bArr = this._currBlock;
     int i = this._currBlockPtr;
     this._currBlockPtr = i + 1;
     bArr[i] = (byte) (b24 >> 16);
     bArr = this._currBlock;
     i = this._currBlockPtr;
     this._currBlockPtr = i + 1;
     bArr[i] = (byte) (b24 >> 8);
     bArr = this._currBlock;
     i = this._currBlockPtr;
     this._currBlockPtr = i + 1;
     bArr[i] = (byte) b24;
     return;
   }
   append(b24 >> 16);
   append(b24 >> 8);
   append(b24);
 }
Exemplo n.º 4
0
 public void write(int b) {
   append(b);
 }
Exemplo n.º 5
0
  /**
   * Convenience method for decoding contents of a Base64-encoded String, using this variant's
   * settings and appending decoded binary data using provided {@link ByteArrayBuilder}.
   *
   * <p>NOTE: builder will NOT be reset before decoding (nor cleared afterwards); assumption is that
   * caller will ensure it is given in proper state, and used as appropriate afterwards.
   *
   * @since 2.3
   * @throws IllegalArgumentException if input is not valid base64 encoded data
   */
  public void decode(String str, ByteArrayBuilder builder) throws IllegalArgumentException {
    int ptr = 0;
    int len = str.length();

    while (ptr < len) {
      // first, we'll skip preceding white space, if any
      char ch;
      do {
        ch = str.charAt(ptr++);
      } while ((ptr < len) && (ch <= INT_SPACE));
      int bits = decodeBase64Char(ch);
      if (bits < 0) {
        _reportInvalidBase64(ch, 0, null);
      }
      int decodedData = bits;
      // then second base64 char; can't get padding yet, nor ws
      if (ptr >= len) {
        _reportBase64EOF();
      }
      ch = str.charAt(ptr++);
      bits = decodeBase64Char(ch);
      if (bits < 0) {
        _reportInvalidBase64(ch, 1, null);
      }
      decodedData = (decodedData << 6) | bits;
      // third base64 char; can be padding, but not ws
      if (ptr >= len) {
        // but as per [JACKSON-631] can be end-of-input, iff not using padding
        if (!usesPadding()) {
          decodedData >>= 4;
          builder.append(decodedData);
          break;
        }
        _reportBase64EOF();
      }
      ch = str.charAt(ptr++);
      bits = decodeBase64Char(ch);

      // First branch: can get padding (-> 1 byte)
      if (bits < 0) {
        if (bits != Base64Variant.BASE64_VALUE_PADDING) {
          _reportInvalidBase64(ch, 2, null);
        }
        // Ok, must get padding
        if (ptr >= len) {
          _reportBase64EOF();
        }
        ch = str.charAt(ptr++);
        if (!usesPaddingChar(ch)) {
          _reportInvalidBase64(ch, 3, "expected padding character '" + getPaddingChar() + "'");
        }
        // Got 12 bits, only need 8, need to shift
        decodedData >>= 4;
        builder.append(decodedData);
        continue;
      }
      // Nope, 2 or 3 bytes
      decodedData = (decodedData << 6) | bits;
      // fourth and last base64 char; can be padding, but not ws
      if (ptr >= len) {
        // but as per [JACKSON-631] can be end-of-input, iff not using padding
        if (!usesPadding()) {
          decodedData >>= 2;
          builder.appendTwoBytes(decodedData);
          break;
        }
        _reportBase64EOF();
      }
      ch = str.charAt(ptr++);
      bits = decodeBase64Char(ch);
      if (bits < 0) {
        if (bits != Base64Variant.BASE64_VALUE_PADDING) {
          _reportInvalidBase64(ch, 3, null);
        }
        decodedData >>= 2;
        builder.appendTwoBytes(decodedData);
      } else {
        // otherwise, our triple is now complete
        decodedData = (decodedData << 6) | bits;
        builder.appendThreeBytes(decodedData);
      }
    }
  }