use of net.schmizz.sshj.sftp.RemoteFile in project AmazeFileManager by TeamAmaze.
the class HybridFile method getInputStream.
/**
* Handles getting input stream for various {@link OpenMode}
* @deprecated use {@link #getInputStream(Context)} which allows handling content resolver
* @return
*/
public InputStream getInputStream() {
InputStream inputStream;
if (isSftp()) {
return SshClientUtils.execute(new SFtpClientTemplate(path) {
@Override
public InputStream execute(SFTPClient client) throws IOException {
final RemoteFile rf = client.open(SshClientUtils.extractRemotePathFrom(path));
return rf.new RemoteFileInputStream() {
@Override
public void close() throws IOException {
try {
super.close();
} finally {
rf.close();
}
}
};
}
});
} else if (isSmb()) {
try {
inputStream = new SmbFile(path).getInputStream();
} catch (IOException e) {
inputStream = null;
e.printStackTrace();
}
} else {
try {
inputStream = new FileInputStream(path);
} catch (FileNotFoundException e) {
inputStream = null;
e.printStackTrace();
}
}
return inputStream;
}
use of net.schmizz.sshj.sftp.RemoteFile in project AmazeFileManager by TeamAmaze.
the class HybridFile method getInputStream.
public InputStream getInputStream(Context context) {
InputStream inputStream;
switch(mode) {
case SFTP:
inputStream = SshClientUtils.execute(new SFtpClientTemplate(path, false) {
@Override
public InputStream execute(final SFTPClient client) throws IOException {
final RemoteFile rf = client.open(SshClientUtils.extractRemotePathFrom(path));
return rf.new RemoteFileInputStream() {
@Override
public void close() throws IOException {
try {
super.close();
} finally {
rf.close();
client.close();
}
}
};
}
});
break;
case SMB:
try {
inputStream = new SmbFile(path).getInputStream();
} catch (IOException e) {
inputStream = null;
e.printStackTrace();
}
break;
case OTG:
ContentResolver contentResolver = context.getContentResolver();
DocumentFile documentSourceFile = OTGUtil.getDocumentFile(path, context, false);
try {
inputStream = contentResolver.openInputStream(documentSourceFile.getUri());
} catch (FileNotFoundException e) {
e.printStackTrace();
inputStream = null;
}
break;
case DROPBOX:
CloudStorage cloudStorageDropbox = dataUtils.getAccount(OpenMode.DROPBOX);
Log.d(getClass().getSimpleName(), CloudUtil.stripPath(OpenMode.DROPBOX, path));
inputStream = cloudStorageDropbox.download(CloudUtil.stripPath(OpenMode.DROPBOX, path));
break;
case BOX:
CloudStorage cloudStorageBox = dataUtils.getAccount(OpenMode.BOX);
inputStream = cloudStorageBox.download(CloudUtil.stripPath(OpenMode.BOX, path));
break;
case GDRIVE:
CloudStorage cloudStorageGDrive = dataUtils.getAccount(OpenMode.GDRIVE);
inputStream = cloudStorageGDrive.download(CloudUtil.stripPath(OpenMode.GDRIVE, path));
break;
case ONEDRIVE:
CloudStorage cloudStorageOneDrive = dataUtils.getAccount(OpenMode.ONEDRIVE);
inputStream = cloudStorageOneDrive.download(CloudUtil.stripPath(OpenMode.ONEDRIVE, path));
break;
default:
try {
inputStream = new FileInputStream(path);
} catch (FileNotFoundException e) {
inputStream = null;
e.printStackTrace();
}
break;
}
return inputStream;
}
use of net.schmizz.sshj.sftp.RemoteFile in project AmazeFileManager by TeamAmaze.
the class HybridFile method getOutputStream.
public OutputStream getOutputStream(Context context) {
OutputStream outputStream;
switch(mode) {
case SFTP:
return SshClientUtils.execute(new SshClientTemplate(path, false) {
@Override
public OutputStream execute(final SSHClient ssh) throws IOException {
final SFTPClient client = ssh.newSFTPClient();
final RemoteFile rf = client.open(SshClientUtils.extractRemotePathFrom(path), EnumSet.of(net.schmizz.sshj.sftp.OpenMode.WRITE, net.schmizz.sshj.sftp.OpenMode.CREAT));
return rf.new RemoteFileOutputStream() {
@Override
public void close() throws IOException {
try {
super.close();
} finally {
rf.close();
client.close();
}
}
};
}
});
case SMB:
try {
outputStream = new SmbFile(path).getOutputStream();
} catch (IOException e) {
outputStream = null;
e.printStackTrace();
}
break;
case OTG:
ContentResolver contentResolver = context.getContentResolver();
DocumentFile documentSourceFile = OTGUtil.getDocumentFile(path, context, true);
try {
outputStream = contentResolver.openOutputStream(documentSourceFile.getUri());
} catch (FileNotFoundException e) {
e.printStackTrace();
outputStream = null;
}
break;
default:
try {
outputStream = FileUtil.getOutputStream(new File(path), context);
} catch (Exception e) {
outputStream = null;
e.printStackTrace();
}
}
return outputStream;
}
Aggregations