use of com.teradata.jaqy.interfaces.Path in project jaqy by Teradata.
the class FileHandler method getString.
@Override
public String getString(JaqyResultSet rs, int column, JaqyInterpreter interpreter) throws Exception {
Object o = rs.getObject(column);
if (o == null)
return null;
String fileName = m_fileInfo.nameGen.newName();
Path file = m_csvFile.getRelativePath(fileName);
if (o instanceof byte[]) {
FileUtils.writeFile(file, (byte[]) o);
} else if (o instanceof Blob) {
Blob blob = (Blob) o;
InputStream is = ((Blob) o).getBinaryStream();
FileUtils.writeFile(file, is, interpreter.getByteBuffer());
is.close();
blob.free();
} else if (o instanceof Clob) {
Clob clob = (Clob) o;
Reader reader = clob.getCharacterStream();
FileUtils.writeFile(file, reader, interpreter.getCharBuffer());
reader.close();
clob.free();
} else if (o instanceof SQLXML) {
SQLXML xml = (SQLXML) o;
Reader reader = xml.getCharacterStream();
FileUtils.writeFile(file, m_fileInfo.charset, reader, interpreter.getCharBuffer());
reader.close();
xml.free();
} else {
FileUtils.writeFile(file, m_fileInfo.charset, o.toString());
}
return fileName;
}
use of com.teradata.jaqy.interfaces.Path in project jaqy by Teradata.
the class CSVImporter method getObject.
@Override
public Object getObject(int index, ParameterInfo paramInfo, JaqyInterpreter interpreter) throws Exception {
try {
String value = m_record.get(index);
if (m_naFilter) {
for (String f : m_naValues) if (value.equals(f))
return null;
}
CSVImportInfo importInfo = m_importInfoMap.get(index);
if (importInfo != null) {
if (value.length() == 0)
return null;
Path file = m_file.getRelativePath(value);
if (!file.isFile())
throw new FileNotFoundException("External file " + file.getPath() + " is not found.");
if (importInfo.charset == null)
return new FileBlob(file);
else
return new FileClob(file, importInfo.charset);
}
if (TypesUtils.isBinary(paramInfo.type))
return StringUtils.getBytesFromHexString(value);
return value;
} catch (ArrayIndexOutOfBoundsException ex) {
throw new IOException("Column " + (index + 1) + " is not found.");
}
}
Aggregations