use of com.mucommander.commons.file.UnsupportedFileOperationException in project mucommander by mucommander.
the class SFTPFile method changeDate.
@Override
public void changeDate(long lastModified) throws IOException, UnsupportedFileOperationException {
try (SFTPConnectionHandler connHandler = (SFTPConnectionHandler) ConnectionPool.getConnectionHandler(connHandlerFactory, fileURL, true)) {
// Makes sure the connection is started, if not starts it
connHandler.checkConnection();
connHandler.channelSftp.setMtime(absPath, (int) (lastModified / 1000));
// Update local attribute copy
fileAttributes.setDate(lastModified);
} catch (Exception e) {
LOGGER.error("failed to change the modification date of " + absPath, e);
throw new IOException(e);
}
}
use of com.mucommander.commons.file.UnsupportedFileOperationException in project mucommander by mucommander.
the class OvirtDataCenter method ls.
@Override
public AbstractFile[] ls() throws IOException, UnsupportedFileOperationException {
String dcName = fileURL.getFilename();
log.debug("listing Data Center {}", dcName);
try (OvirtConnHandler connHandler = getConnHandler()) {
DataCenter dc = Utils.getDataCenter(connHandler, dcName);
return Utils.getStorageDomains(connHandler, dc.id()).stream().filter(sd -> sd.type() == StorageDomainType.DATA).map(this::toFile).filter(Objects::nonNull).toArray(AbstractFile[]::new);
}
}
use of com.mucommander.commons.file.UnsupportedFileOperationException in project mucommander by mucommander.
the class SevenZipArchiveFile method getEntryInputStream.
// ////////////////////////////////////////
// AbstractROArchiveFile implementation //
// ////////////////////////////////////////
@Override
public InputStream getEntryInputStream(final ArchiveEntry entry, ArchiveEntryIterator entryIterator) throws IOException, UnsupportedFileOperationException {
final IInArchive sevenZipFile = openSevenZipFile();
/* ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
// threadPool.execute(new Runnable() {
// public void run() {
// BufferedOutputStream bufferedOut = new BufferedOutputStream(out);
try {
int arrays [] = new int[1];
for(int i = 0 ; i < sevenZipFile.size() ; i++) {
// System.out.println("check " + sevenZipFile.getEntry(i).getName());
if (entry.getPath().equals(sevenZipFile.getEntry(i).getName())) {
System.out.println("entry.getPath = " + entry.getPath() + ", sevenZipFile.getEntry(i).getName() " + sevenZipFile.getEntry(i).getName());
arrays[0] = i;
break;
}
}
MuArchiveExtractCallback extractCallbackSpec = new MuArchiveExtractCallback(os);//, entry.getPath());
extractCallbackSpec.Init(sevenZipFile);
try {
sevenZipFile.Extract(arrays, 1, IInArchive.NExtract_NAskMode_kExtract , extractCallbackSpec);
}
catch (Exception e) {
e.printStackTrace();
// return;
}
// sevenZipFile.Extract(null, -1, IInArchive.NExtract_NAskMode_kExtract , extractCallbackSpec);
try
{
Thread.sleep(1000); // do nothing for 1000 miliseconds (1 second)
}
catch(InterruptedException e)
{
e.printStackTrace();
}
System.out.println("stopped");
// bufferedOut.flush();
}
catch (Exception e) {
LOGGER.info("Error while retrieving 7zip entry {}", e);
System.out.println("Error while retrieving 7zip entry {}");
}
finally {
// try { bufferedOut.close(); }
// catch(IOException e) {
// // Not much we can do about it
// e.printStackTrace();
// }
try { in.close(); }
catch(IOException e) {
// Not much we can do about it
e.printStackTrace();
}
try { sevenZipFile.close(); }
catch(IOException e) {
// Not much we can do about it
e.printStackTrace();
}
}
// }
// });
return new ByteArrayInputStream(os.toByteArray()); */
final int[] arrays = new int[1];
for (int i = 0; i < sevenZipFile.size(); i++) {
// System.out.println("check " + sevenZipFile.getEntry(i).getName());
if (entry.getPath().equals(sevenZipFile.getEntry(i).getName())) {
arrays[0] = i;
break;
}
}
final CircularByteBuffer cbb = new CircularByteBuffer(CircularByteBuffer.INFINITE_SIZE);
new Thread(new Runnable() {
public void run() {
MuArchiveExtractCallback extractCallbackSpec = new MuArchiveExtractCallback(cbb.getOutputStream(), entry.getPath());
extractCallbackSpec.Init(sevenZipFile);
try {
sevenZipFile.Extract(arrays, 1, IInArchive.NExtract_NAskMode_kExtract, extractCallbackSpec);
} catch (Exception e) {
e.printStackTrace();
// return;
}
}
}).start();
return cbb.getInputStream();
}
use of com.mucommander.commons.file.UnsupportedFileOperationException in project mucommander by mucommander.
the class DropboxFile method ls.
@Override
public AbstractFile[] ls() throws IOException, UnsupportedFileOperationException {
try (DropboxConnectionHandler connHandler = getConnHandler()) {
DbxUserFilesRequests r = connHandler.getDbxClient().files();
ListFolderResult result;
try {
result = r.listFolder(getId());
} catch (DbxException e) {
LOGGER.error("failed to list folder", e);
return null;
}
return result.getEntries().stream().filter(meta -> !(meta instanceof DeletedMetadata)).map(meta -> {
FileURL url = (FileURL) fileURL.clone();
url.setPath(meta.getPathDisplay());
return new DropboxFile(url, this, meta);
}).toArray(AbstractFile[]::new);
}
}
use of com.mucommander.commons.file.UnsupportedFileOperationException in project mucommander by mucommander.
the class OvirtDisk method getInputStream.
@Override
public InputStream getInputStream() throws IOException, UnsupportedFileOperationException {
try (OvirtConnHandler connHandler = getConnHandler()) {
ImageTransfer transfer = Utils.addImageTransfer(connHandler, disk.id(), ImageTransferDirection.DOWNLOAD);
final String transferId = transfer.id();
Utils.sleep(500);
do {
transfer = Utils.getImageTransfer(connHandler, transferId);
} while (isTransferInitializing(transfer));
log.debug("Transfer session has been created!");
System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
URL url = getDestinationUrl(transfer);
HttpsURLConnection https = (HttpsURLConnection) url.openConnection();
https.setSSLSocketFactory(Utils.setTrustStore(connHandler.getCertificate()));
https.setDoInput(true);
https.setRequestProperty("GET", url.getPath());
https.setRequestMethod("GET");
return new BufferedInputStream(https.getInputStream()) {
public void close() throws IOException {
try {
int responseCode = https.getResponseCode();
log.info("Finished downloading disk " + (responseCode == 200 ? "successfully" : "with failure") + " (response code = " + responseCode + ")");
if (responseCode != 200)
throw new IOException("Failed to download disk");
} catch (Exception e) {
log.error("Failed to download file", e);
} finally {
try (OvirtConnHandler connHandler = getConnHandler()) {
super.close();
Utils.finalizeImageTransfer(connHandler, transferId);
https.disconnect();
}
}
}
};
}
}
Aggregations