All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.api.client.util.StringUtils Maven / Gradle / Ivy

Go to download

Google HTTP Client Library for Java. Functionality that works on all supported Java platforms, including Java 5 (or higher) desktop (SE) and web (EE), Android, and Google App Engine.

There is a newer version: 1.44.1
Show newest version
/*
 * Copyright (c) 2012 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */

package com.google.api.client.util;

import java.io.UnsupportedEncodingException;


/**
 * Utilities for strings.
 *
 * 

* Some of these methods are a proxy for version 1.6 (or newer) of the Apache Commons Codec * {@link StringUtils} implementation. This is needed in order to support platforms like Android * which already include an older version of the Apache Commons Codec (Android includes version * 1.3). To avoid a dependency library conflict, this library includes a reduced private copy of * version 1.6 (or newer) of the Apache Commons Codec (using a tool like jarjar). *

* * @since 1.8 * @author Yaniv Inbar */ public class StringUtils { /** * Line separator to use for this OS, i.e. {@code "\n"} or {@code "\r\n"}. * * @since 1.8 */ public static final String LINE_SEPARATOR = System.getProperty("line.separator"); /** * Encodes the given string into a sequence of bytes using the UTF-8 charset, storing the result * into a new byte array. * * @param string the String to encode, may be null * @return encoded bytes, or null if the input string was null * @throws IllegalStateException Thrown when the charset is missing, which should be never * according the the Java specification. * @see Standard charsets * @see org.apache.commons.codec.binary.StringUtils#getBytesUtf8(String) * @since 1.8 */ public static byte[] getBytesUtf8(String string) { return org.apache.commons.codec.binary.StringUtils.getBytesUtf8(string); } /** * Constructs a new String by decoding the specified array of bytes using the UTF-8 * charset. * * @param bytes The bytes to be decoded into characters * @return A new String decoded from the specified array of bytes using the UTF-8 * charset, or null if the input byte array was null. * @throws IllegalStateException Thrown when a {@link UnsupportedEncodingException} is caught, * which should never happen since the charset is required. * @see org.apache.commons.codec.binary.StringUtils#newStringUtf8(byte[]) * @since 1.8 */ public static String newStringUtf8(byte[] bytes) { return org.apache.commons.codec.binary.StringUtils.newStringUtf8(bytes); } private StringUtils() { } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy