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://");
            Session session = SessionFactory.createSession(false);
            Context ctx = ContextFactory.createContext("Globus"); 
            ctx.setAttribute(Context.USERPROXY, "x509up");  
            ctx.setAttribute(Context.CERTREPOSITORY, "/.globus/certificates/");  
            FileFactory.createFile(session, fileUrl, Flags.CREATE.getValue());
            FileFactory.createFileOutputStream(session, fileUrl, false); 
                          // => Exception: AlreadyExists: File already exists: srm://
            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?

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);

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


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

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.


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

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