Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
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
–
–
–
–
–
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?
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.