protected synchronized String convertBigNumberToString( BigDecimal number ) throws KettleValueException { if ( number == null ) { return null; } try { return getDecimalFormat( bigNumberFormatting ).format( number ); } catch ( Exception e ) { throw new KettleValueException( toString() + " : couldn't convert BigNumber to String ", e ); } }
break; default: throw new KettleFileException( toString() + " : Unable to serialize data type " + getType() ); throw new KettleFileException( toString() + " : Unknown storage type " + getStorageType() ); throw new RuntimeException( toString() + " : There was a data type error: the data type of " + object.getClass().getName() + " object [" + object + "] does not correspond to value meta [" + toStringMeta() + "]" ); } catch ( IOException e ) { throw new KettleFileException( toString() + " : Unable to write value data to output stream", e );
protected byte[] convertStringToBinaryString( String string ) throws KettleValueException { if ( string == null ) { return null; } if ( Utils.isEmpty( stringEncoding ) ) { return string.getBytes(); } else { try { return string.getBytes( stringEncoding ); } catch ( UnsupportedEncodingException e ) { throw new KettleValueException( toString() + " : couldn't convert String to Binary with specified string encoding [" + stringEncoding + "]", e ); } } }
return (byte[]) index[( (Integer) object ).intValue()]; default: throw new KettleValueException( toString() + " : Unknown storage type " + storageType + " specified." ); throw new KettleValueException( toString() + " : I don't know how to convert a date to binary." ); case TYPE_STRING: switch ( storageType ) { return convertStringToBinaryString( (String) index[( (Integer) object ).intValue()] ); default: throw new KettleValueException( toString() + " : Unknown storage type " + storageType + " specified." ); throw new KettleValueException( toString() + " : I don't know how to convert a number to binary." ); case TYPE_INTEGER: throw new KettleValueException( toString() + " : I don't know how to convert an integer to binary." ); case TYPE_BIGNUMBER: throw new KettleValueException( toString() + " : I don't know how to convert a bignumber to binary." ); case TYPE_BOOLEAN: throw new KettleValueException( toString() + " : I don't know how to convert a boolean to binary." ); case TYPE_SERIALIZABLE: throw new KettleValueException( toString() + " : I don't know how to convert a serializable to binary." ); throw new KettleValueException( toString() + " : Unknown type " + type + " specified." );
protected synchronized Double convertStringToNumber( String string ) throws KettleValueException { string = Const.trimToType( string, getTrimType() ); // see if trimming needs // to be performed before // conversion if ( Utils.isEmpty( string ) ) { return null; } try { DecimalFormat format = getDecimalFormat( false ); Number number; if ( lenientStringToNumber ) { number = format.parse( string ); } else { ParsePosition parsePosition = new ParsePosition( 0 ); number = format.parse( string, parsePosition ); if ( parsePosition.getIndex() < string.length() ) { throw new KettleValueException( toString() + " : couldn't convert String to number : non-numeric character found at position " + ( parsePosition.getIndex() + 1 ) + " for value [" + string + "]" ); } } return new Double( number.doubleValue() ); } catch ( Exception e ) { throw new KettleValueException( toString() + " : couldn't convert String to number ", e ); } }
protected synchronized Long convertStringToInteger( String string ) throws KettleValueException { string = Const.trimToType( string, getTrimType() ); // see if trimming needs // to be performed before // conversion if ( Utils.isEmpty( string ) ) { return null; } try { Number number; if ( lenientStringToNumber ) { number = new Long( getDecimalFormat( false ).parse( string ).longValue() ); } else { ParsePosition parsePosition = new ParsePosition( 0 ); number = getDecimalFormat( false ).parse( string, parsePosition ); if ( parsePosition.getIndex() < string.length() ) { throw new KettleValueException( toString() + " : couldn't convert String to number : non-numeric character found at position " + ( parsePosition.getIndex() + 1 ) + " for value [" + string + "]" ); } } return new Long( number.longValue() ); } catch ( Exception e ) { throw new KettleValueException( toString() + " : couldn't convert String to Integer", e ); } }
/** * Create a new Value meta object. * * @param inputStream * @throws KettleFileException * @throws KettleEOFException * @deprecated in favor of a combination of {@link ValueMetaFactory}.createValueMeta() and the loadMetaData() method. */ @Deprecated public ValueMetaBase( DataInputStream inputStream ) throws KettleFileException, KettleEOFException { this(); try { type = inputStream.readInt(); } catch ( EOFException e ) { throw new KettleEOFException( e ); } catch ( IOException e ) { throw new KettleFileException( toString() + " : Unable to read value metadata from input stream", e ); } readMetaData( inputStream ); }
throw new KettleValueException( toString() + " : couldn't convert String to number : non-numeric character found at position " + ( parsePosition.getIndex() + 1 ) + " for value [" + string + "]" ); return new BigDecimal( string ); } catch ( NumberFormatException ex ) { throw new KettleValueException( toString() + " : couldn't convert string value '" + string + "' to a big number.", ex );
throw new KettleValueException( toString() + ": unable to make copy of value type: " + getType() );
throw new RuntimeException( "Unable to verify if [" + toString() + "] is null or not because of an error:" + e.toString(), e );
protected synchronized Date convertStringToDate( String string ) throws KettleValueException { string = Const.trimToType( string, getTrimType() ); // see if trimming needs // to be performed before // conversion if ( Utils.isEmpty( string ) ) { return null; } try { ParsePosition pp = new ParsePosition( 0 ); Date result = getDateFormat( TYPE_DATE ).parse( string, pp ); if ( pp.getErrorIndex() >= 0 ) { // error happen throw new ParseException( string, pp.getErrorIndex() ); } // some chars can be after pp.getIndex(). That means, not full value was parsed. For example, for value // "25-03-1918 11:54" and format "dd-MM-yyyy", value will be "25-03-1918 00:00" without any exception. // If there are only spaces after pp.getIndex() - that means full values was parsed return result; } catch ( ParseException e ) { String dateFormat = ( getDateFormat() != null ) ? getDateFormat().toPattern() : "null"; throw new KettleValueException( toString() + " : couldn't convert string [" + string + "] to a date using format [" + dateFormat + "] on offset location " + e.getErrorOffset(), e ); } }
protected synchronized String convertNumberToString( Double number ) throws KettleValueException { if ( number == null ) { if ( !outputPaddingEnabled || length < 1 ) { return null; } else { // Return strings padded to the specified length... // This is done for backward compatibility with 2.5.x // We just optimized this a bit... // String[] emptyPaddedStrings = Const.getEmptyPaddedStrings(); if ( length < emptyPaddedStrings.length ) { return emptyPaddedStrings[length]; } else { return Const.rightPad( "", length ); } } } try { DecimalFormat format = getDecimalFormat( false ); // When conversion masks are different, we must ensure the number precision is not lost if ( this.conversionMask != null && storageMetadata != null && !this.conversionMask.equals( storageMetadata.getConversionMask() ) ) { format.setMaximumFractionDigits( 50 ); } return format.format( number ); } catch ( Exception e ) { throw new KettleValueException( toString() + " : couldn't convert Number to String ", e ); } }
return new String( binary, encoding ); } catch ( UnsupportedEncodingException e ) { throw new KettleValueException( toString() + " : couldn't convert binary value to String with specified string encoding [" + stringEncoding + "]", e );
protected synchronized String convertIntegerToString( Long integer ) throws KettleValueException { if ( integer == null ) { if ( !outputPaddingEnabled || length < 1 ) { return null; } else { // Return strings padded to the specified length... // This is done for backward compatibility with 2.5.x // We just optimized this a bit... // String[] emptyPaddedStrings = Const.getEmptyPaddedStrings(); if ( length < emptyPaddedStrings.length ) { return emptyPaddedStrings[length]; } else { return Const.rightPad( "", length ); } } } try { return getDecimalFormat( false ).format( integer ); } catch ( Exception e ) { throw new KettleValueException( toString() + " : couldn't convert Long to String ", e ); } }
return InetAddress.getByAddress( readBinary( inputStream ) ); default: throw new KettleFileException( toString() + " : Unable to de-serialize data of type " + getType() ); throw new KettleFileException( toString() + " : Unknown storage type " + getStorageType() ); throw e; } catch ( IOException e ) { throw new KettleFileException( toString() + " : Unable to read value data from input stream", e );
return meta2.getBinary( data2 ); default: throw new KettleValueException( toString() + " : I can't convert the specified value to data type : " + getType() );
break; default: throw new KettleValueException( toString() + " : We can't convert data type " + getTypeDesc() + " to an original (V2) Value" );
return meta2.getBinary( data2 ); default: throw new KettleValueException( toString() + " : I can't convert the specified value to data type : " + getType() );
return value.getBytes(); default: throw new KettleValueException( toString() + " : We can't convert original data type " + value.getTypeDesc() + " to a primitive data type" );
return getDate( data ); default: throw new KettleValueException( toString() + " : I can't convert the specified value to data type : " + conversionMetadata.getType() );