use of org.pentaho.di.core.exception.KettleFileException in project pentaho-kettle by pentaho.
the class JobEntryCopyFilesDialog method getFileSelectionAdapter.
protected SelectionAdapter getFileSelectionAdapter() {
return new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
FileObject selectedFile = null;
try {
// Get current file
FileObject rootFile = null;
FileObject initialFile = null;
FileObject defaultInitialFile = null;
String original = wFields.getActiveTableItem().getText(wFields.getActiveTableColumn());
if (original != null) {
String fileName = jobMeta.environmentSubstitute(original);
if (fileName != null && !fileName.equals("")) {
try {
initialFile = KettleVFS.getFileObject(fileName);
} catch (KettleException ex) {
initialFile = KettleVFS.getFileObject("");
}
defaultInitialFile = KettleVFS.getFileObject("file:///c:/");
rootFile = initialFile.getFileSystem().getRoot();
} else {
defaultInitialFile = KettleVFS.getFileObject(Spoon.getInstance().getLastFileOpened());
}
}
if (rootFile == null) {
rootFile = defaultInitialFile.getFileSystem().getRoot();
initialFile = defaultInitialFile;
}
VfsFileChooserDialog fileChooserDialog = Spoon.getInstance().getVfsFileChooserDialog(rootFile, initialFile);
fileChooserDialog.defaultInitialFile = defaultInitialFile;
selectedFile = fileChooserDialog.open(shell, new String[] { "file" }, "file", true, null, new String[] { "*.*" }, FILETYPES, true, VfsFileChooserDialog.VFS_DIALOG_OPEN_FILE_OR_DIRECTORY, false, false);
if (selectedFile != null) {
String url = selectedFile.getURL().toString();
wFields.getActiveTableItem().setText(wFields.getActiveTableColumn(), url);
}
} catch (KettleFileException ex) {
} catch (FileSystemException ex) {
}
}
};
}
use of org.pentaho.di.core.exception.KettleFileException in project pentaho-kettle by pentaho.
the class Translator method loadJava.
private String loadJava(String javaFile, String propertiesFilename, String entry) throws KettleFileException {
if (Utils.isEmpty(entry)) {
return "";
}
try {
String filename = ROOT + "/" + javaFile;
StringBuilder content = new StringBuilder(5000);
FileInputStream stream = new FileInputStream(filename);
try {
int c = 0;
while ((c = stream.read()) != -1) {
content.append((char) c);
}
} finally {
stream.close();
}
return content.toString();
} catch (Exception e) {
throw new KettleFileException(propertiesFilename + ": Unable to load file [" + javaFile + "] for key [" + entry + "]", e);
}
}
use of org.pentaho.di.core.exception.KettleFileException in project pentaho-kettle by pentaho.
the class Translator method readFiles.
public void readFiles(String directory) throws KettleFileException {
log.logBasic("Scanning directory: " + directory);
try {
File file = new File(directory);
File[] entries = file.listFiles();
for (int i = 0; i < entries.length; i++) {
File entry = entries[i];
if (entry.isDirectory()) {
if (!entry.getName().startsWith(".svn")) {
readFiles(directory + "/" + entry.getName());
}
} else {
if (entry.isFile()) {
if (entry.getName().endsWith(".properties")) {
// Load this one!
String filename = directory + "/" + entry.getName();
log.logBasic("Reading properties file: " + filename + " (" + entry.getAbsolutePath() + ")");
Properties properties = new Properties();
properties.load(new FileInputStream(entry));
// Store it in the map:
files.put(filename, properties);
}
}
}
}
// get the list of distinct directories:
// at the same time, keep a list of available locales
//
directories = new Hashtable<String, Integer>(files.size());
locales = new Hashtable<String, Boolean>(10);
for (String filename : files.keySet()) {
String path = getPath(filename);
// is it already in there?
Integer num = directories.get(path);
if (num != null) {
num = Integer.valueOf(num.intValue() + 1);
} else {
num = Integer.valueOf(1);
}
directories.put(path, num);
// What's the locale?
String locale = getLocale(filename);
locales.put(locale, Boolean.TRUE);
if (locale.charAt(2) != '_') {
log.logError("This i18n locale file is not conform the Kettle standard: " + filename);
}
}
} catch (Exception e) {
throw new KettleFileException("Unable to get all files from directory [" + ROOT + "]", e);
}
}
use of org.pentaho.di.core.exception.KettleFileException in project pentaho-kettle by pentaho.
the class ValueMetaBase method readMetaData.
/**
* Load the attributes of this particular value meta object from the input stream. Loading the type is not handled
* here, this should be read from the stream previously!
*
* @param inputStream
* the input stream to read from
* @throws KettleFileException
* In case there was a IO problem
* @throws KettleEOFException
* If we reached the end of the stream
*/
@Override
public void readMetaData(DataInputStream inputStream) throws KettleFileException, KettleEOFException {
//
try {
// Handle storage type
storageType = inputStream.readInt();
// Read the data in the index
switch(storageType) {
case STORAGE_TYPE_INDEXED:
int indexSize = inputStream.readInt();
if (indexSize < 0) {
index = null;
} else {
index = new Object[indexSize];
for (int i = 0; i < indexSize; i++) {
switch(type) {
case TYPE_STRING:
index[i] = readString(inputStream);
break;
case TYPE_NUMBER:
index[i] = readNumber(inputStream);
break;
case TYPE_INTEGER:
index[i] = readInteger(inputStream);
break;
case TYPE_DATE:
index[i] = readDate(inputStream);
break;
case TYPE_BIGNUMBER:
index[i] = readBigNumber(inputStream);
break;
case TYPE_BOOLEAN:
index[i] = readBoolean(inputStream);
break;
case TYPE_BINARY:
index[i] = readBinary(inputStream);
break;
default:
throw new KettleFileException(toString() + " : Unable to de-serialize indexed storage type for data type " + getType());
}
}
}
break;
case STORAGE_TYPE_BINARY_STRING:
// well..
if (inputStream.readBoolean()) {
storageMetadata = new ValueMetaBase(inputStream);
}
break;
default:
break;
}
// name
name = readString(inputStream);
// length & precision
length = inputStream.readInt();
precision = inputStream.readInt();
// Origin
origin = readString(inputStream);
// Comments
comments = readString(inputStream);
// formatting Mask, decimal, grouping, currency
conversionMask = readString(inputStream);
decimalSymbol = readString(inputStream);
groupingSymbol = readString(inputStream);
currencySymbol = readString(inputStream);
trimType = inputStream.readInt();
// Case sensitivity
caseInsensitive = inputStream.readBoolean();
// Collator locale
setCollatorLocale(Locale.forLanguageTag(readString(inputStream)));
// Collator disabled
collatorDisabled = inputStream.readBoolean();
// Collator strength
collatorStrength = inputStream.readInt();
// Sorting type
sortedDescending = inputStream.readBoolean();
// Output padding?
outputPaddingEnabled = inputStream.readBoolean();
// is date parsing lenient?
//
dateFormatLenient = inputStream.readBoolean();
// What is the date format locale?
//
String strDateFormatLocale = readString(inputStream);
if (Utils.isEmpty(strDateFormatLocale)) {
dateFormatLocale = null;
} else {
dateFormatLocale = EnvUtil.createLocale(strDateFormatLocale);
}
// What is the time zone to use for date parsing?
//
String strTimeZone = readString(inputStream);
if (Utils.isEmpty(strTimeZone)) {
dateFormatTimeZone = TimeZone.getDefault();
} else {
dateFormatTimeZone = EnvUtil.createTimeZone(strTimeZone);
}
// is string to number parsing lenient?
lenientStringToNumber = inputStream.readBoolean();
} catch (EOFException e) {
throw new KettleEOFException(e);
} catch (IOException e) {
throw new KettleFileException(toString() + " : Unable to read value metadata from input stream", e);
}
}
use of org.pentaho.di.core.exception.KettleFileException in project pentaho-kettle by pentaho.
the class ValueMetaTimestamp method readData.
@Override
public Object readData(DataInputStream inputStream) throws KettleFileException, KettleEOFException, SocketTimeoutException {
try {
// Is the value NULL?
if (inputStream.readBoolean()) {
// done
return null;
}
switch(storageType) {
case STORAGE_TYPE_NORMAL:
// Handle Content -- only when not NULL
long time = inputStream.readLong();
int nanos = inputStream.readInt();
Timestamp timestamp = new Timestamp(time);
timestamp.setNanos(nanos);
return timestamp;
case STORAGE_TYPE_BINARY_STRING:
return readBinaryString(inputStream);
case STORAGE_TYPE_INDEXED:
// just an index: 4-bytes should be enough.
return readSmallInteger(inputStream);
default:
throw new KettleFileException(toString() + " : Unknown storage type " + getStorageType());
}
} catch (EOFException e) {
throw new KettleEOFException(e);
} catch (SocketTimeoutException e) {
throw e;
} catch (IOException e) {
throw new KettleFileException(toString() + " : Unable to read value timestamp data from input stream", e);
}
}
Aggregations