home list archives users mailing list

Subject: Re: FileReplace activity does not work with input stream

Date view Thread view Subject view Author view Attachment view

From: Stephan Rudlof (rudlof@Ontoprise.DE)
Date: Apr 05, 2006 16:43

Hello Amy,

On 04-Apr-06 7:49 PM, Amy Krause wrote:
> Hi,
>
>>> The DeliverFromURL activity produces blocks of byte arrays whereas the
>>> ReplaceFile activity expects blocks of Strings - you can't pipe output
>>> from the delivery activity to ReplaceFile.
>>

>> Thanks for the info: interestingly there hasn't been any error message
>> at server or client side.
>
> That's a bug. Can you enter this into our query system?

Done; see
  http://bugs.ogsadai.org.uk/show_bug.cgi?id=58
.

>...

> You could also use the ReadFile activity to read a file from the file
> system and pipe it to the FileWriting activity. The ReadFile activity
> produces strings so it's compatible with FileWriting. It's located in
> package indexedfiles but works for all files.
> http://www.ogsadai.org.uk/documentation/ogsadai-wsi-2.1/doc/interaction/activities/indexedfiles/readFile.html
>
> Actually, this should solve your problem.

I've followed your advice as far as possible, with some - but not full - success:

<code>
    public void testSolution_1() throws Exception {
        String sourceHandle = "http://localhost:8080/wsrf/services/ogsadai/DataService";
        String sourceResource = "FilesResource";

        DataService service = GenericServiceFetcher.getInstance().getDataService(sourceHandle, sourceResource);
        ReadFile deliverFrom = new ReadFile("in.txt");
        
        FileReplace target = new FileReplace("out.txt", FileWriting.BOF, FileWriting.TO_EOF, false);

        // For removing '<file>' at the beginning and '</file>' at the end of the output file.
        FileDelete postProcessing_startTag = new FileDelete("out.txt", FileWriting.BOF, "<file>".length(), false);
        FileDelete postProcessing_endTag = new FileDelete("out.txt", "</file>", "1", false);

        target.setInput(deliverFrom.getOutput());
        
        /* for explicit synchronisation */
        Flow flow = new Flow();
        flow.addChild(deliverFrom);
        flow.addChild(target);
        Sequence sequence = new Sequence();
        sequence.addChild(flow);
        sequence.addChild(postProcessing_startTag);
        sequence.addChild(postProcessing_endTag);
        
        ActivityRequest request = new ActivityRequest();
        request.add(sequence);

        /* probably unsafe
        request.add(deliverFrom);
        request.add(target);
        request.add(postProcessing_startTag);
        request.add(postProcessing_endTag);
        */
        
        printRequestAsXML(request);
        Response response = service.perform(request);
        System.out.println("Response:\n" + response.getAsString());
        System.out.println(response.toString());
    }
</code>

Notes
-----
- FileDelete activities are necessary, since before there are '<file>' and '</file>' tags added to the content of the input file at beginning and end of output file:
'from input file' in input file becomes '<file>from input file</file>' in output file (content without quotes).
Is this a feature or a bug?

- The first FileDelete activity is straightforward, but I haven't found another way as using regex matching for removing the last '</file>': this is ugly and would *not* work, if this tag already arises in the input file contents (its first appearance would be deleted).

- A solution to the latter problem *could* be to somehow use the file size of the input file to compute the offset at the end of the output file needed for the second FileDelete activity: but is the length of a file seen as text - always? - (size in bytes / 2)?

Best regards,
Stephan

>...

-- 
Stephan Rudlof (rudlof@ontoprise.de)
Professional Services
ontoprise GmbH - know how to use Know-how
---
Amalienbadstraße 36 (Raumfabrik 29); 76227 Karlsruhe
Phone: +49 (0) 721 509 809 46; FAX: +49 (0) 509 809 11
http://www.ontoprise.de

Date view Thread view Subject view Author view Attachment view