org.jmythapi.utils
Class EncodingUtils

java.lang.Object
  extended by org.jmythapi.utils.EncodingUtils

public class EncodingUtils
extends Object


Nested Class Summary
static class EncodingUtils.DateTimePattern
          Date pattern used to parse dates.
 
Field Summary
static String DATE_PATTERN
           
static String NULL_DATE_TIME
           
static String NULL_DAY
           
static String NULL_TIME
           
static String TIME_PATTERN
           
static String TIMEZONE_UTC
           
static Class<?>[][] VALUE_OF_ARGS
          valueOf methods that are supported by decodeString(java.lang.Class, org.jmythapi.protocol.ProtocolVersion, java.lang.String)
 
Method Summary
static Date aggregateDateTime(Date day, Time time, boolean isUTC)
           
static Boolean decodeBoolean(String value)
           
static Boolean decodeBoolean(String value, Boolean onEmptyValue)
           
static long decodeLong(int[] values)
          Deprecated. 66
static long decodeLong(String value1, String value2)
          Deprecated. 66
static
<E> E
decodeString(Class<E> clazz, ProtocolVersion protoVersion, int dbVersion, boolean isUTC, String value)
           
static
<E> E
decodeString(Class<E> clazz, ProtocolVersion protoVersion, int dbVersion, boolean isUTC, String value, E onEmptyValue)
          Converts the given value-string into the specified class.
static
<E> E
decodeString(Class<E> clazz, ProtocolVersion protoVersion, String value)
          Converts the given value-string into the specified class.
static String[] encodeLong(long value)
          Deprecated. 66
static
<S,T> String
encodeObject(Class<S> sourceType, ProtocolVersion versionNr, int dbVersion, boolean isUTC, S value, Class<T> targetType, String onNullValue)
           
static
<S,T> String
encodeObject(Class<S> sourceType, ProtocolVersion versionNr, S value, Class<T> targetType, String onNullValue)
           
static String formatDateTime(Date date, boolean isUTC)
          Formats the given date as string.
static String formatDateTimeToUnixTimestamp(Date date)
           
static String formatDay(Date day, boolean isUTC)
           
static String formatTime(Date time, boolean isUTC)
           
static String generateId(Integer id, Date date)
           
static int getDaysDiff(Date start, Date end)
           
static String getFormattedFileSize(Locale locale, long bytes)
           
static String getFormattedFileSize(long bytes)
           
static String getFormattedTitle(String title, String subTitle)
           
static int[] getHourMinutesLength(int duration)
           
static int getHoursDiff(Date start, Date end)
           
static int getMinutesAfterMidnight(Date start)
           
static int getMinutesDiff(Date start, Date end)
           
static int getMinutesDiff(long start, long end)
           
static int getSecondsDiff(Date start, Date end)
           
static int getSecondsDiff(long start, long end)
           
static Date parseDate(String value, boolean isUTC)
          Parses the given string into a date object.
static Date parseDay(String dayString, boolean isUTC)
           
static Time parseTime(String timeString, boolean isUTC)
           
static Object[] splitId(String idString, boolean isUTC)
          Splits a id-string into the channel-id and start-date part.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TIMEZONE_UTC

public static final String TIMEZONE_UTC
See Also:
Constant Field Values

DATE_PATTERN

public static final String DATE_PATTERN
See Also:
Constant Field Values

TIME_PATTERN

public static final String TIME_PATTERN
See Also:
Constant Field Values

NULL_DAY

public static final String NULL_DAY
See Also:
Constant Field Values

NULL_TIME

public static final String NULL_TIME
See Also:
Constant Field Values

NULL_DATE_TIME

public static final String NULL_DATE_TIME
See Also:
Constant Field Values

VALUE_OF_ARGS

public static final Class<?>[][] VALUE_OF_ARGS
valueOf methods that are supported by decodeString(java.lang.Class, org.jmythapi.protocol.ProtocolVersion, java.lang.String)

Method Detail

formatDay

public static String formatDay(Date day,
                               boolean isUTC)
See Also:
parseDay(java.lang.String, boolean)

parseDay

public static Date parseDay(String dayString,
                            boolean isUTC)
See Also:
parseDay(java.lang.String, boolean)

formatTime

public static String formatTime(Date time,
                                boolean isUTC)
See Also:
parseTime(java.lang.String, boolean)

parseTime

public static Time parseTime(String timeString,
                             boolean isUTC)
See Also:
formatTime(java.util.Date, boolean)

aggregateDateTime

public static Date aggregateDateTime(Date day,
                                     Time time,
                                     boolean isUTC)

formatDateTime

public static String formatDateTime(Date date,
                                    boolean isUTC)
Formats the given date as string.

The returned string is in the format EncodingUtils.DateTimePattern.PROTOCOL_DATE_FORMAT

Parameters:
date - the date to format
isUTC - if the date is in UTC format
Returns:
the output string.

formatDateTimeToUnixTimestamp

public static String formatDateTimeToUnixTimestamp(Date date)

parseDate

public static Date parseDate(String value,
                             boolean isUTC)
Parses the given string into a date object.

The date string can be in one of the following formats

Parameters:
value - the date string.
isUTC - if the date is in UTC format
Returns:
the parsed date or null if the date is invalid or can not be parsed

encodeLong

public static String[] encodeLong(long value)
Deprecated. 66

Converts a 64 bit long value into two signed 32 bit integer values.

See Also:
decodeencode.cpp

decodeLong

public static long decodeLong(String value1,
                              String value2)
Deprecated. 66

Converts two signed 32 bit integer values into a 64 bit long value.

See Also:
decodeencode.cpp

decodeLong

public static long decodeLong(int[] values)
Deprecated. 66

Converts two sigend 32 bit integer values into a 64 bit long value.

See Also:
decodeencode.cpp

decodeString

public static <E> E decodeString(Class<E> clazz,
                                 ProtocolVersion protoVersion,
                                 String value)
Converts the given value-string into the specified class.

The conversion is done by calling one of the following static functions (see: VALUE_OF_ARGS):

Usage example:

  ProgramInfo programInfo = ....;
  ProgramFlags programFlags = EncodingUtils.decodeString(
      // the target class to convert the string to 
      ProgramFlags.class,
      // the protocol version
      this.protoVersion,
      // the string value of the given argument
      programInfo.getResponseArgument(ProgramInfo.Props.PROGRAM_FLAGS)
  );
 

Type Parameters:
E - the target type
Parameters:
clazz - the target class
protoVersion - the protocol- or database-version
value - the value as string
Returns:
the converted value. If the given value is null then null is returned

decodeString

public static <E> E decodeString(Class<E> clazz,
                                 ProtocolVersion protoVersion,
                                 int dbVersion,
                                 boolean isUTC,
                                 String value)

decodeString

public static <E> E decodeString(Class<E> clazz,
                                 ProtocolVersion protoVersion,
                                 int dbVersion,
                                 boolean isUTC,
                                 String value,
                                 E onEmptyValue)
Converts the given value-string into the specified class.

The conversion is done by calling one of the following static functions (see: VALUE_OF_ARGS):

Additionally the following simple types are supported:

Usage example:

  ProgramInfo programInfo = ....;
  ProgramFlags programFlags = EncodingUtils.decodeString(
      // the target class to convert the string to 
      ProgramFlags.class,
      // the protocol version
      this.protoVersion,
      // the string value of the given argument
      programInfo.getResponseArgument(ProgramInfo.Props.PROGRAM_FLAGS)
  );
 

Type Parameters:
E - the target type
Parameters:
clazz - the target class
protoVersion - the protocol- or database-version
value - the value as string.
Returns:
If the given value is null then the value of onEmptyValue is returned

decodeBoolean

public static Boolean decodeBoolean(String value)

decodeBoolean

public static Boolean decodeBoolean(String value,
                                    Boolean onEmptyValue)

encodeObject

public static <S,T> String encodeObject(Class<S> sourceType,
                                        ProtocolVersion versionNr,
                                        S value,
                                        Class<T> targetType,
                                        String onNullValue)

encodeObject

public static <S,T> String encodeObject(Class<S> sourceType,
                                        ProtocolVersion versionNr,
                                        int dbVersion,
                                        boolean isUTC,
                                        S value,
                                        Class<T> targetType,
                                        String onNullValue)

getMinutesAfterMidnight

public static int getMinutesAfterMidnight(Date start)

getSecondsDiff

public static int getSecondsDiff(long start,
                                 long end)

getSecondsDiff

public static int getSecondsDiff(Date start,
                                 Date end)

getMinutesDiff

public static int getMinutesDiff(long start,
                                 long end)

getMinutesDiff

public static int getMinutesDiff(Date start,
                                 Date end)

getHoursDiff

public static int getHoursDiff(Date start,
                               Date end)

getDaysDiff

public static int getDaysDiff(Date start,
                              Date end)

getHourMinutesLength

public static int[] getHourMinutesLength(int duration)

getFormattedFileSize

public static String getFormattedFileSize(long bytes)

getFormattedFileSize

public static String getFormattedFileSize(Locale locale,
                                          long bytes)

getFormattedTitle

public static String getFormattedTitle(String title,
                                       String subTitle)

generateId

public static String generateId(Integer id,
                                Date date)

splitId

public static Object[] splitId(String idString,
                               boolean isUTC)
Splits a id-string into the channel-id and start-date part.

Parameters:
idString - the unique- program- or -recording-id
Returns:
an array containing the channel-id and start-date.


Copyright © 2008-2013. All Rights Reserved.