SRM - file output stream

Added by Hajnal Akos almost 6 years ago

Dear Developers,

When I create a file and then try to open its output stream for writing, I get exception in either append or overwrite mode.

Here is the code:

import org.ogf.saga.context.*;
import org.ogf.saga.file.*;
import org.ogf.saga.namespace.*;
import org.ogf.saga.session.*;
import org.ogf.saga.url.*;

public class Srm {
    public static void main(String[] args) {
        try {
            URL fileUrl = URLFactory.createURL("srm://grid143.kfki.hu/dpm/kfki.hu/home/hungrid/akostest/test.txt");
            Session session = SessionFactory.createSession(false);
            Context ctx = ContextFactory.createContext("Globus"); 
            ctx.setAttribute(Context.USERPROXY, "x509up");  
            ctx.setAttribute(Context.CERTREPOSITORY, "/.globus/certificates/");  
            session.addContext(ctx);
            FileFactory.createFile(session, fileUrl, Flags.CREATE.getValue());
            FileFactory.createFileOutputStream(session, fileUrl, false); 
                          // => Exception: AlreadyExists: File already exists: srm://grid143.kfki.hu/.../test.txt
            FileFactory.createFileOutputStream(session, fileUrl, true); 
                          // => Exception: BadParameter: APPEND is not supported by this adaptor 
        } catch (Exception e) { e.printStackTrace(); }
    }
}

As I remember the same sequence worked for other protocols, so I don't know what is the problem. Creation flags are different in the case of srm? Or something else is needed?

Thanks,
Akos Hajnal

[main] INFO  data.SRM22DataAdaptor  - SRM Version is v2.2 [backend_type=DPM;backend_version=1.8.6-0;]

Replies (3)

RE: SRM - file output stream - Added by Hajnal Akos almost 6 years ago

Just one more note. It seems that without explicitely creating the file, both input- and output streams work well:

        byte [] content = new byte [] {'c', 'o', 'n', 't', 'e', 'n', 't'};
        FileOutputStream fos = FileFactory.createFileOutputStream(session, fileUrl, false);
        fos.write(content, 0, content.length);
        fos.close();

        FileInputStream fis = FileFactory.createFileInputStream(session, fileUrl);
        int b; while ((b = fis.read()) > 0) { System.out.print((char) b); }
        fis.close();

Akos

RE: SRM - file output stream - Added by Schwarz Lionel almost 6 years ago

Akos,
The boolean parameter of FileFactory.createFileOutputStream is the 'append flag', not 'overwrite'.
If I remember well, SRM does not support modification of a file (append or rewrite).
So if you want to create a FileOutputStream, you have to make sure beforehands that the file does not exist already.

Lionel

RE: SRM - file output stream - Added by Hajnal Akos almost 6 years ago

Ok, thanks, I am new to this "write-once" stuff...
Akos

(1-3/3)