/** * Get file encoding. * * @param metaA * The ValueMetaInterface * @param dataA * The value (filename) * @return file encoding. * @deprecated Use {@link ValueDataUtil#getFileEncoding(ValueMetaInterface, Object, boolean)} instead */ @Deprecated public static String getFileEncoding( ValueMetaInterface metaA, Object dataA ) throws KettleValueException { String encoding = null; try { encoding = getFileEncoding( metaA, dataA, true ); } catch ( KettleFileNotFoundException e ) { throw new KettleValueException(); } return encoding; }
@Test public void getFileEncodingWithFailIfNoFileTest() throws Exception { String path = getClass().getResource( "txt-sample.txt" ).getPath(); String encoding = ValueDataUtil.getFileEncoding( new ValueMetaString(), path, true ); assertEquals( "US-ASCII", encoding ); }
@Test( expected = KettleFileNotFoundException.class ) public void getFileEncodingFailIfNoFileTest() throws KettleFileNotFoundException, KettleValueException { String nonExistingPath = "nonExistingPath"; ValueDataUtil.getFileEncoding( new ValueMetaString(), nonExistingPath, true ); }
@Test public void getFileEncodingTest() throws Exception { String path = getClass().getResource( "txt-sample.txt" ).getPath(); String encoding = ValueDataUtil.getFileEncoding( new ValueMetaString(), path ); assertEquals( "US-ASCII", encoding ); }
@Test public void getFileEncodingWithoutFailIfNoFileTest() throws Exception { String path = getClass().getResource( "txt-sample.txt" ).getPath(); String encoding = ValueDataUtil.getFileEncoding( new ValueMetaString(), path, false ); assertEquals( "US-ASCII", encoding ); }
@Test( expected = KettleValueException.class ) public void getFileEncodingMissingFileTest() throws KettleValueException { String nonExistingPath = "nonExistingPath"; ValueDataUtil.getFileEncoding( new ValueMetaString(), nonExistingPath ); }
@Test public void getFileEncodingNoFailIfNoFileTest() throws Exception { String nonExistingPath = "nonExistingPath"; String encoding = ValueDataUtil.getFileEncoding( new ValueMetaString(), nonExistingPath, false ); assertNull( encoding ); }
@Test public void getFileEncodingNullPathNoFailTest() throws Exception { String encoding = ValueDataUtil.getFileEncoding( new ValueMetaString(), null, false ); assertNull( encoding ); }
@Test public void getFileEncodingNullPathFailTest() throws KettleFileNotFoundException, KettleValueException { String encoding = ValueDataUtil.getFileEncoding( new ValueMetaString(), null, true ); assertNull( encoding ); }
@Test public void getFileEncodingNullPathTest() throws Exception { assertNull( ValueDataUtil.getFileEncoding( new ValueMetaString(), null ) ); }
break; case CalculatorMetaFunction.CALC_GET_FILE_ENCODING: // Get file encoding from a file A calcData[index] = ValueDataUtil.getFileEncoding( metaA, dataA, meta.isFailIfNoFile() ); resultType = CalculatorMetaFunction.calcDefaultResultType[calcType]; break;