Convert a byte array to a JSONArray.
@param bytes a UTF-8 encoded string representing a JSON array.
@return the parsed JSON array
@throws WebbException in case of error (usually a parsing error due to invalid JSON)
495303
public static JSONArray toJsonArray(byte[] bytes) {
        String json;
        try {
            json = new String(bytes, Const.UTF8);
            return new JSONArray(json);
        } catch (UnsupportedEncodingException e) {
            throw new WebbException(e);
        } catch (JSONException e) {
            throw new WebbException("payload is not a valid JSON array", e);
        }
    }
928810
public static RubyArray<Byte> toList(byte[] bytes) {
    RubyArray<Byte> list = Ruby.Array.create();
    for (byte b : bytes) {
      list.add(b);
    }
    return list;
  }
767721
private static String toAsciiString(byte[] bytes) {
        for(int i = 0; i < bytes.length; i++) {
            if(bytes[i] < 0) return null;
        }
        char[] chars = new char[bytes.length];
        for(int i = 0; i < bytes.length; i++) {
            chars[i] = (char)bytes[i];
        }
        return new String(chars);
    }
276492
public static AppDescriptor deserializeFrom(byte[] bytes) {
        try {
            ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
            ObjectInputStream ois = new ObjectInputStream(bais);
            return (AppDescriptor) ois.readObject();
        } catch (IOException e) {
            throw E.ioException(e);
        } catch (ClassNotFoundException e) {
            throw E.unexpected(e);
        }
    }
38354
public static byte[] toByteArray(URL url) throws IOException {
        try (InputStream inputStream = url.openStream()) {
            return ByteStreams.toByteArray(inputStream);
        }
    }
201393
private static String bytesToHex(byte[] bytes) {
        char[] hexChars = new char[bytes.length * 2];
        for (int i = 0; i < bytes.length; i++) {
            int v = bytes[i] & 0xFF;
            hexChars[i * 2] = hexArray[v >>> 4];
            hexChars[i * 2 + 1] = hexArray[v & 0x0F];
        }
        return new String(hexChars);
    }
635872
public Object parse(byte [] bytes, String charset) {
        if (bytes == null) {
            throw new IllegalArgumentException("bytes must not be null");
        }

        if (charset == null) {
            throw new IllegalArgumentException("charset must not be null");
        }

        Object content;
        content = createParser().parse(bytes, charset);
        return content;
    }
1244177
public static final Object deserialize(byte[] bytes) throws Exception {
        final boolean trace = TraceComponent.isAnyTracingEnabled();
        if (trace && tc.isEntryEnabled())
            Tr.entry(tc, "deserialize");

        Object o;
        try {
            ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
            ObjectInputStream oin = new ObjectInputStream(bis);
            o = oin.readObject();
            oin.close();
        } catch (IOException e) {
            FFDCFilter.processException(e, ConnectorService.class.getName(), "151");
            if (trace && tc.isEntryEnabled())
                Tr.exit(tc, "deserialize", new Object[] { toString(bytes), e });
            throw e;
        }

        if (trace && tc.isEntryEnabled())
            Tr.exit(tc, "deserialize", o == null ? null : o.getClass());
        return o;
    }
1278745
public static String bytesToBase64Url(byte[] bytes) {
        String result = (new String(Base64.encodeBase64(bytes), MESSAGE_ENCODING)).replace("=", "").replace("\\", "").replace('+', '-')
                .replace('/', '_');
        return result;
    }
691392
public static String bytesToBase64Str(byte[] bytes) {
        if (ArrayUtils.isEmpty(bytes)) {
            return null;
        }
        Base64.Encoder encoder = Base64.getEncoder();
        String base64Str = encoder.encodeToString(bytes);
        return base64Str;
    }
53118
public static Mono<byte[]> collectByteArray(Flux<byte[]> bytes) {
        return bytes
            .reduceWith(ByteArrayOutputStream::new, (prev, next) -> {
                try {
                    prev.write(next);
                } catch (IOException e) {
                    throw Exceptions.propagate(e);
                }
                return prev;
            })
            .map(ByteArrayOutputStream::toByteArray);
    }
615686
public static byte[] readBytes(URL url) throws IOException {
        URLConnection conn = url.openConnection();
        try {
            return readBytes(conn);
        } finally {
            close(conn);
        }
    }
372188
public static String string(byte[] bytes) {
    if (bytes == null) {
      return null;
    }
    try {
      return new String(bytes, ENCODING);
    } catch (UnsupportedEncodingException e) {
      log.error("UnsupportedEncodingException ", e);
      throw new RuntimeException(e);
    }
  }
539292
public static byte[] decode(byte[] bytes) {
    ByteArrayInputStream in = new ByteArrayInputStream(bytes);
    // calculate the length of the resulting output.
    // in general it will be at most 3/4 the size of the input
    // but the input length must be divisible by four.
    // If it isn't the next largest size that is divisible
    // by four is used.
    int mod;
    int length = bytes.length;
    if ((mod = length % 4) != 0) {
      length += 4 - mod;
    }
    length = length * 3 / 4;
    ByteArrayOutputStream out = new ByteArrayOutputStream(length);
    try {
      decode(in, out, false);
    } catch (IOException x) {
      // This can't happen.
      // The input and output streams were constructed
      // on memory structures that don't actually use IO.
      throw new RuntimeException(x);
    }
    return out.toByteArray();
  }
947063
public static byte[] readAll(InputStream bytes) throws IOException {
    ByteArrayOutputStream builder = new ByteArrayOutputStream();
    int read = bytes.read();
    while (read != -1) {
      builder.write(read);
      read = bytes.read();
    }
    builder.flush();
    bytes.close();
    return builder.toByteArray();
  }
533292
public byte[] toJsonBytes(final Object resource) throws UnsupportedEncodingException {
        if (resource instanceof JSONObject) {
            final JSONObject json = (JSONObject) resource;
            return json.toString().getBytes("UTF-8");
        }

        final HashMap<String, Object> out = new HashMap<String, Object>();
        final JSONObject res = beanSerialize(resource, out);
        if (res == null || res.length() == 0) {
            return new JSONObject(out).toString().getBytes("UTF-8");
        } else {
            return res.toString().getBytes("UTF-8");
        }
    }
627170
public static String bytes2String(byte[] bytes) {
    try {
      final int len = bytes.length;
      char[] charArray = UTF8.getCharArray(len);
      for (int i = 0; i < bytes.length; i++) {
        if (bytes[i] < UTF8.MIN_ASCII_CODE) {
          // non-ASCII codepoints' higher bytes
          // are of the form (10xxxxxx), hence the bytes
          // represent a non-ASCII string
          // do expensive conversion
          return new String(bytes, utf8charsetName);
        }
        // copy to temporary array
        charArray[i] = (char) bytes[i];
      }
      // only ASCII bytes, do fast conversion
      // using bytes as actual characters
      return new String(charArray, 0, len);
    } catch (UnsupportedEncodingException e) {
      assert false : "UTF8 encoding is not supported ";
    }
    return null;
  }