5

I have this problem that I am creating a file but this is creating empty file.

I am using a API of Dropbox, Code of Dropbox operate good, but I don't Know that I don't fine. I have used 2º and 3º Codes for my app, this is operating good.

This operate by hierarchically. I am sending outputStream for the fuction. But this is empty.

I am using outputStream because I need that this operates with outputstream.

1º Code(Class Test || Call):

File tempFile=new File("C:\\PRUEBAS_TFG\\cloud.png"); if ( ! tempFile.exists() ) { tempFile.createNewFile(); } 
File file = new File("C:\\PRUEBAS_TFG\\cloud.png");
OutputStream outputStream = new FileOutputStream(file);
catmanager.downloadFilesToItem(catmanager.getAllListCatalog().get(0), catmanager.getAllListCatalog().get(0).getItems().get(2), listFile, outputStream);
outputStream.close();

2º Code(Class catmanager || 1ºbody):

public void downloadFilesToItem(Catalog catalog, Item item, List<String> files, OutputStream output){
    try{
        String fsPath;
        fsPath = pathCatalog(catalog);
        getFSManager().changeDirectoryConfigNPath(fsPath+"/"+item.getName()+"_item");
        for(int i = 0;i<files.size();i++){
            getFSManager().downloadFile(files.get(i), output);
        }
    }catch(Exception e){
        e.printStackTrace();
    }
}

3ºCode(Class FSManager || 2ºbody)

public void downloadFile(String fileName, OutputStream output) throws IOException{//Aqui deveria Buscar el Fichero Funciona por que da la casualidad que esta el fichero en la primera nube 
    /** Cogemos la lista de FS del usuario */
    List<IFileSystem> aux = getFileSystemsUser();

    for(int i = 0; i < aux.size();i++){
        /** Se realiza la Funcionalidad del metodo*/
        System.out.println(aux.get(i).toString());
        try{
            aux.get(i).downloadFile(_listPath.get(i)+"/"+fileName, output);
            i = aux.size()+1;
        }catch(IOException e) {

        }
    }
}

4ºCode(Class aux Dropbox || API Dropbox):

public void downloadFile(String fileName, OutputStream aux) throws IOException{
    try{
        getDbxClient().getFile(fileName, null, aux);
    }catch(IOException e){
        throw e;
    }catch(DbxException u){
        throw new IOException(u.getCause());
    }
}

Thanks Advance.

2
  • Could you provide a minimal (and better formatted) example, please? :-) We’d be gald to help. :-)
    – Ole V.V.
    Aug 10, 2016 at 11:50
  • thanks for the advice , I have modified the post Aug 10, 2016 at 12:07

2 Answers 2

1

You are using one FileOutputStream for downloading a list of file. Do you expect to merge the files (in one image), or something like that?

If is is not expected, I certainly would not pass the FileOutputStream as input parameter of your successive calls (2,3,4), but an instance of File representing the folder. In your last method (4), create (and close after download) a new FileOutputStream for a file in that folder. Something like

public void downloadFile(String fileName, File folder) throws IOException{
  OutputStream outputStream = new FileOutputStream(new File(folder, filename));
  try{
    getDbxClient().getFile(fileName, null, outputStream );
  }catch(IOException e){
    throw e;
  }catch(DbxException u){
    throw new IOException(u.getCause());
  }finally {
    outputstream.close();
  }
}
1
  • The problem is that I need hierarchically of class for my app in JEE. I need that OutputStream arrive to Dropbox class and the dropbox class arrive to test class with the container of OutputStream. Thanks for your interest Aug 10, 2016 at 16:21
0

I suppose you'll have to flush (see corresponding method) the outputsteam to your file (and close it). The Dropbox API is dealing with OutputStream, but certainly do not care that you want to write a file.

you can have a look to thee following example.

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.