Search in sources :

Example 1 with UnsupportedFileOperationException

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);
    }
}
Also used : IOException(java.io.IOException) SftpException(com.jcraft.jsch.SftpException) IOException(java.io.IOException) UnsupportedFileOperationException(com.mucommander.commons.file.UnsupportedFileOperationException) AuthException(com.mucommander.commons.file.AuthException)

Example 2 with UnsupportedFileOperationException

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);
    }
}
Also used : Objects(java.util.Objects) Logger(org.slf4j.Logger) StorageDomain(org.ovirt.engine.sdk4.types.StorageDomain) FileOperation(com.mucommander.commons.file.FileOperation) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) DataCenter(org.ovirt.engine.sdk4.types.DataCenter) StorageDomainType(org.ovirt.engine.sdk4.types.StorageDomainType) FileURL(com.mucommander.commons.file.FileURL) AbstractFile(com.mucommander.commons.file.AbstractFile) UnsupportedFileOperationException(com.mucommander.commons.file.UnsupportedFileOperationException) DataCenter(org.ovirt.engine.sdk4.types.DataCenter)

Example 3 with UnsupportedFileOperationException

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();
}
Also used : IInArchive(com.mucommander.commons.file.archive.sevenzip.provider.SevenZip.Archive.IInArchive) CircularByteBuffer(com.mucommander.commons.util.CircularByteBuffer) IOException(java.io.IOException) UnsupportedFileOperationException(com.mucommander.commons.file.UnsupportedFileOperationException)

Example 4 with UnsupportedFileOperationException

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);
    }
}
Also used : FileFactory(com.mucommander.commons.file.FileFactory) FilePermissions(com.mucommander.commons.file.FilePermissions) ConnectionPool(com.mucommander.commons.file.connection.ConnectionPool) BufferedInputStream(java.io.BufferedInputStream) Date(java.util.Date) ConnectionHandlerFactory(com.mucommander.commons.file.connection.ConnectionHandlerFactory) LoggerFactory(org.slf4j.LoggerFactory) WriteMode(com.dropbox.core.v2.files.WriteMode) ListFolderResult(com.dropbox.core.v2.files.ListFolderResult) BufferedOutputStream(java.io.BufferedOutputStream) CreateFolderResult(com.dropbox.core.v2.files.CreateFolderResult) ByteArrayInputStream(java.io.ByteArrayInputStream) ProtocolFile(com.mucommander.commons.file.protocol.ProtocolFile) FolderMetadata(com.dropbox.core.v2.files.FolderMetadata) SpaceUsage(com.dropbox.core.v2.users.SpaceUsage) DbxUserFilesRequests(com.dropbox.core.v2.files.DbxUserFilesRequests) PermissionBits(com.mucommander.commons.file.PermissionBits) PermissionType(com.mucommander.commons.file.PermissionType) DeletedMetadata(com.dropbox.core.v2.files.DeletedMetadata) OutputStream(java.io.OutputStream) Logger(org.slf4j.Logger) UploadSessionCursor(com.dropbox.core.v2.files.UploadSessionCursor) PermissionAccess(com.mucommander.commons.file.PermissionAccess) IOException(java.io.IOException) RandomAccessInputStream(com.mucommander.commons.io.RandomAccessInputStream) ConnectionHandler(com.mucommander.commons.file.connection.ConnectionHandler) PathUtils(com.mucommander.commons.file.util.PathUtils) FileMetadata(com.dropbox.core.v2.files.FileMetadata) DbxException(com.dropbox.core.DbxException) RandomAccessOutputStream(com.mucommander.commons.io.RandomAccessOutputStream) CommitInfo(com.dropbox.core.v2.files.CommitInfo) FileOperation(com.mucommander.commons.file.FileOperation) UnsupportedFileOperation(com.mucommander.commons.file.UnsupportedFileOperation) FileURL(com.mucommander.commons.file.FileURL) Metadata(com.dropbox.core.v2.files.Metadata) AbstractFile(com.mucommander.commons.file.AbstractFile) UnsupportedFileOperationException(com.mucommander.commons.file.UnsupportedFileOperationException) InputStream(java.io.InputStream) DbxUserFilesRequests(com.dropbox.core.v2.files.DbxUserFilesRequests) FileURL(com.mucommander.commons.file.FileURL) ListFolderResult(com.dropbox.core.v2.files.ListFolderResult) DeletedMetadata(com.dropbox.core.v2.files.DeletedMetadata) DbxException(com.dropbox.core.DbxException)

Example 5 with UnsupportedFileOperationException

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();
                    }
                }
            }
        };
    }
}
Also used : ImageTransfer(org.ovirt.engine.sdk4.types.ImageTransfer) BufferedInputStream(java.io.BufferedInputStream) IOException(java.io.IOException) URL(java.net.URL) FileURL(com.mucommander.commons.file.FileURL) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnsupportedFileOperationException(com.mucommander.commons.file.UnsupportedFileOperationException)

Aggregations

UnsupportedFileOperationException (com.mucommander.commons.file.UnsupportedFileOperationException)6 IOException (java.io.IOException)6 FileURL (com.mucommander.commons.file.FileURL)4 AbstractFile (com.mucommander.commons.file.AbstractFile)2 FileOperation (com.mucommander.commons.file.FileOperation)2 BufferedInputStream (java.io.BufferedInputStream)2 BufferedOutputStream (java.io.BufferedOutputStream)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)2 ImageTransfer (org.ovirt.engine.sdk4.types.ImageTransfer)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 DbxException (com.dropbox.core.DbxException)1 CommitInfo (com.dropbox.core.v2.files.CommitInfo)1 CreateFolderResult (com.dropbox.core.v2.files.CreateFolderResult)1 DbxUserFilesRequests (com.dropbox.core.v2.files.DbxUserFilesRequests)1 DeletedMetadata (com.dropbox.core.v2.files.DeletedMetadata)1 FileMetadata (com.dropbox.core.v2.files.FileMetadata)1 FolderMetadata (com.dropbox.core.v2.files.FolderMetadata)1