I have this code:
InputStream fileContent = filePart.getInputStream();
if(client.isConnected()){
client.setFileType(FTP.BINARY_FILE_TYPE);
System.out.println("Aqui si tiene: "+fileContent.available());
BufferedInputStream buffIn = null;
buffIn = new BufferedInputStream(fileContent);
client.enterLocalPassiveMode();
boolean foo = client.storeFile(imgBD.get("nombre"), buffIn);
//si se guardó bien en el FTP entonces guardamos en el disco local del servidor
if(foo){
String fileName = getSubmittedFileName(filePart);
File folder = new File(ruta+File.separator+imgBD.get("carpeta"));
if(!folder.exists()){
folder.mkdirs();
}
File file = new File(ruta+File.separator+imgBD.get("carpeta"), imgBD.get("nombre"));
System.out.println("Aqui ya es cero "+fileContent.available());
Files.copy(fileContent, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
}
I have to pass my fileContent object in a BufferedInputStream so I can save it to an FTP, so far so good, but that line seems to cause my InputStream object ( fileContent ) to be converted to 0 bytes . In my first System.out.println it prints me the bytes that the object has and in the second System.out.println it prints me a 0, so it does create an image in the directory that I want but with 0 bytes, that is, is a file with the pure name.
How do I use my InputStream object even after it is used by BufferedInputStream ?
From an InputStream create two equal InputStreams: