Encode and Decode with base64 Problem

I have a tif image that I need to map into an XML document. I am accessing the tif via ftp in binary transfer mode. I get the content and encode using pub.string:base64Encode. I map the data to the XML document.

Now I want to confirm the data was encoded properly, so I read the XML document back into IS as a string, map the base64 encoded string to pub.string:base64Decode and write the data back to a file as bytes. But I can not open the file.

I then try to read the same tif in using pub.file.getFile as a byte array encode in base64 then decode and write the file back to disk. I get the same problem.

Any help???

Are you flushing/closing the file after writing?

I have flushed and closed all output streams. Also, I am using the utf 8 encoding.

In the code below the variable “bytes” is type Object
See code below:

FileOutputStream fos=new FileOutputStream(filename);

ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(bytes);
oos.flush();
oos.close();
bos.close();
byte data = bos.toByteArray();

fos.write(data);
fos.flush();
fos.close();

Why is “bytes” an Object? Based on your description, it should be byte. A byte array is not an object and using ObjectOutputStream here is probably the issue.

Assuming that the input to the service is the byte array (which will be an “object” in the pipeline–but it isn’t really) then the service to write to the file can be as simple as this (omitting try/catch for clarity):
[highlight=Java]IDataCursor pipelineCursor = pipeline.getCursor();
String filename = IDataUtil.getString(pipelineCursor, “filename”);
byte bytes = (byte)IDataUtil.get(pipelineCursor, “bytes”);

FileOutputStream fos=new FileOutputStream(filename);
fos.write(bytes);
fos.flush();
fos.close();
pipelineCursor.destroy();[/highlight]

Thanks Rob. I saw that but I wasn’t sure it made a difference. I can successfully run the encode and decode test now.