Hi, I had the same problem.
In order to solve it, i've made my own TypeConverter.
public class CdnFileConverter implements TypeConverter {
/**
* Convertit un fichier local en InputStream SANS charger le fichier en
memoire, contrairement au convertisseur Camel.
*
* @param file the local file
* @return the input stream
* @throws IOException Signals that an I/O exception has occurred.
*/
public static InputStream genericFileToInputStream(GenericFile<File>
file) throws IOException {
return new
BufferedInputStream(FileUtils.openInputStream(file.getFile()));
}
/*
* (non-Javadoc)
*
* @see org.apache.camel.TypeConverter#convertTo(java.lang.Class,
java.lang.Object)
*/
@Override
public <T> T convertTo(Class<T> type, Object value) {
return convertTo(type, null, value);
}
/*
* (non-Javadoc)
*
* @see org.apache.camel.TypeConverter#convertTo(java.lang.Class,
org.apache.camel.Exchange, java.lang.Object)
*/
@SuppressWarnings("unchecked")
@Override
public <T> T convertTo(Class<T> type, Exchange exchange, Object value) {
// this method with the Exchange parameter will be preferred by
Camel to invoke
// this allows you to fetch information from the exchange during
conversions
// such as an encoding parameter or the likes
T converted = null;
// Si c'est un fichier distant, on laisse le convertisseur Camel
faire son travail
if (InputStream.class.isAssignableFrom(type) &&
RemoteFile.class.isInstance(value)) {
RemoteFile< ? > file = (RemoteFile< ? >) value;
try {
converted = (T)
GenericFileConverter.genericFileToInputStream(file, exchange);
}
//CHECKSTYLE:OFF
catch (IOException e) {
// converted reste null
}
//CHECKSTYLE:ON
}
// Si c'est un fichier local, on lance la conversion sans charger le
fichier en mémoire
else if (InputStream.class.isAssignableFrom(type) &&
GenericFile.class.isInstance(value)) {
GenericFile<File> file = (GenericFile<File>) value;
try {
converted = (T) genericFileToInputStream(file);
}
//CHECKSTYLE:OFF
catch (IOException e) {
// converted reste null
}
//CHECKSTYLE:ON
}
// Sinon converted reste null : Camel va tenter une conversion avec
un FallbackConverter
return converted;
}
/*
* (non-Javadoc)
*
* @see
org.apache.camel.TypeConverter#mandatoryConvertTo(java.lang.Class,
java.lang.Object)
*/
@Override
public <T> T mandatoryConvertTo(Class<T> type, Object value) {
return convertTo(type, null, value);
}
/*
* (non-Javadoc)
*
* @see
org.apache.camel.TypeConverter#mandatoryConvertTo(java.lang.Class,
org.apache.camel.Exchange, java.lang.Object)
*/
@Override
public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange, Object
value) {
return convertTo(type, exchange, value);
}
--
View this message in context:
http://camel.465427.n5.nabble.com/Errors-with-SFTP-producer-and-large-files-tp4757404p4757568.html
Sent from the Camel - Users mailing list archive at Nabble.com.