Reputation: 1666
I am trying to transfer file from SFTP to SharePoint folder.
I have used JSCH Library to connect to SFTP.
Following is my code snippet to upload file.
private void sharePointUpload(String driveId, String targetLocation, InputStream inputStream, String fileName) throws FileNotFoundException, IOException {
UploadSession uploadSession = this.graphServiceClient.drives().byId(driveId).root().itemWithPath(targetLocation +"/"+ fileName)
.createUploadSession(this.uploadParams).buildRequest().post();
byte[] inputStreamByteArray = IOUtils.toByteArray(inputStream);
LargeFileUploadTask<DriveItem> largeFileUploadTask = new LargeFileUploadTask<DriveItem>
(uploadSession, this.graphServiceClient, new ByteArrayInputStream(inputStreamByteArray), inputStreamByteArray.length, DriveItem.class);
largeFileUploadTask.upload(MAXIMUM_CHUNK_SIZE);
}
I am getting error java.io.IOException: inputstream is closed at IOUtils.toByteArray(inputStream)
What will be the root cause ?
Error Logs
Update :
Code Snippet to Get InputStream
for (int i = 0; i < list.size(); i++) {
sourcefilenamelist = list.get(i);
logger.log(proccessingFileLogText + sourcefilenamelist);
if (targetFilenameflag.equalsIgnoreCase("false")) {
targetFilename = sourcefilenamelist;
}
InputStream stream = sourceChannelSftp.get(sourceLocation + '/' + sourcefilenamelist);
InputStreamDetails decryptEncryptInputStreamDetails = decryptEncryptInputStream(stream, targetFilename, sourceEncryption, targetEncryption, jobjsource);
stream = decryptEncryptInputStreamDetails.getInputStream();
targetFilename = decryptEncryptInputStreamDetails.getFileName();
try {
sharePointUpload(targetDriveId, targetLocation, stream, targetFilename);
} catch (ClientException e) {
logger.log(" Graph API ClientException : ");
logger.log( "e.getMessage() :- " + e.getMessage() );
logger.log( "RootCauseMessage :- " + ExceptionUtils.getRootCauseMessage(e) );
// isSQSMessageRetry = true;
throw e;
}
...
...
...
}
PS: Few files are transferred from List
Upvotes: 2
Views: 7246
Reputation: 2676
supposing the stream works, but once the stream is read, it will close, try checking if it's being read somewhere else.
Upvotes: 0
Reputation: 11
This line is giving you a closed InputStream:
InputStream stream = sourceChannelSftp.get(sourceLocation + '/' + sourcefilenamelist);
Perhaps the sourceLocation
argument that you are sending to it is not correct?
Upvotes: 0
Reputation: 27
You are providing it with closed InputStream when the method is being called. Make sure the InputStream you are providing is open and initialized.
Upvotes: 0