org.xwiki.crypto.internal
Class Convert

java.lang.Object
  extended by org.xwiki.crypto.internal.Convert

public final class Convert
extends java.lang.Object

Utility class for various string conversions, such as base64 encoding and decoding and conversion to byte array. Supports conversion of strings containing base64 encoded data. The conversion uses UTF-8 because it is always available and base64 alphabet is a subset of UTF-8.

Since:
2.5M1
Version:
$Id$

Method Summary
static java.lang.String bytesToString(byte[] bytes)
          Convert byte array into a string using UTF-8 encoding.
static byte[] fromBase64(byte[] base64Encoded)
          Decode the base64 encoded data array.
static byte[] fromBase64String(java.lang.String base64Encoded)
          Decode the base64 encoded data represented as string.
static byte[] fromBase64String(java.lang.String withBase64EncodedContent, java.lang.String beginningMarker, java.lang.String endMarker)
          Decode the base64 encoded data represented as string.
static java.lang.String getContentBetween(java.lang.String input, java.lang.String beginningMarker, java.lang.String endMarker)
          Get substring between beginningMarker and endMarker.
static java.lang.String getNewline()
           
static byte[] stringToBytes(java.lang.String string)
          Convert string to byte array using the same encoding as for base64 conversion.
static byte[] stringToBytes(java.lang.String withBase64EncodedContent, java.lang.String beginningMarker, java.lang.String endMarker)
          Convert string to byte array using the same encoding as for base64 conversion.
static byte[] toBase64(byte[] data)
          Encode given data and return the base64 encoded result as a byte array.
static java.lang.String toBase64String(byte[] data)
          Encode given data and return the base64 encoded result as string (no line breaks).
static java.lang.String toChunkedBase64String(byte[] data)
          Encode given data and return the base64 encoded result as string, chunking it into several lines of the default length (64).
static java.lang.String toChunkedBase64String(byte[] data, int lineLength)
          Encode given data and return the base64 encoded result as string, chunking it into several lines of the given length.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

toBase64String

public static java.lang.String toBase64String(byte[] data)
Encode given data and return the base64 encoded result as string (no line breaks).

Parameters:
data - the data to encode
Returns:
base64 encoded data

toChunkedBase64String

public static java.lang.String toChunkedBase64String(byte[] data)
Encode given data and return the base64 encoded result as string, chunking it into several lines of the default length (64).

Parameters:
data - the data to encode
Returns:
base64 encoded data

toChunkedBase64String

public static java.lang.String toChunkedBase64String(byte[] data,
                                                     int lineLength)
Encode given data and return the base64 encoded result as string, chunking it into several lines of the given length.

Parameters:
data - the data to encode
lineLength - maximal line length
Returns:
base64 encoded data

toBase64

public static byte[] toBase64(byte[] data)
Encode given data and return the base64 encoded result as a byte array.

Parameters:
data - the data to encode
Returns:
base64 encoded data array

fromBase64String

public static byte[] fromBase64String(java.lang.String withBase64EncodedContent,
                                      java.lang.String beginningMarker,
                                      java.lang.String endMarker)
Decode the base64 encoded data represented as string. Ignore anything before beginningMarker or after endMarker.

Parameters:
withBase64EncodedContent - string containing base64 encoded data.
beginningMarker - anything in the string which is not after this will be ignored.
endMarker - anything in the string which is not before this will be ignored.
Returns:
the decoded data array

fromBase64String

public static byte[] fromBase64String(java.lang.String base64Encoded)
Decode the base64 encoded data represented as string.

Parameters:
base64Encoded - base64 encoded data string
Returns:
the decoded data array

fromBase64

public static byte[] fromBase64(byte[] base64Encoded)
Decode the base64 encoded data array.

Parameters:
base64Encoded - base64 encoded data
Returns:
the decoded data array

getContentBetween

public static java.lang.String getContentBetween(java.lang.String input,
                                                 java.lang.String beginningMarker,
                                                 java.lang.String endMarker)
Get substring between beginningMarker and endMarker.

Parameters:
input - string to get content from.
beginningMarker - anything in the string which is not after this will be ignored.
endMarker - anything in the string which is not before this will be ignored.
Returns:
part of input between beginningMarker and endMarker.

stringToBytes

public static byte[] stringToBytes(java.lang.String withBase64EncodedContent,
                                   java.lang.String beginningMarker,
                                   java.lang.String endMarker)
Convert string to byte array using the same encoding as for base64 conversion. Ignore anything before beginningMarker or after endMarker.

Parameters:
withBase64EncodedContent - string containing base64 encoded data.
beginningMarker - anything in the string which is not after this will be ignored.
endMarker - anything in the string which is not before this will be ignored.
Returns:
byte array containing the characters from the string (still in Base64 format)

stringToBytes

public static byte[] stringToBytes(java.lang.String string)
Convert string to byte array using the same encoding as for base64 conversion.

Parameters:
string - the string to convert
Returns:
byte array containing the characters from the string

bytesToString

public static java.lang.String bytesToString(byte[] bytes)
Convert byte array into a string using UTF-8 encoding.

Parameters:
bytes - to make into a string
Returns:
new String from the given bytes.

getNewline

public static java.lang.String getNewline()
Returns:
a newline string, dependent on platform.


Copyright © 2004-2011 XWiki. All Rights Reserved.