cancel
Showing results for 
Search instead for 
Did you mean: 

empty file, java mapping issue

milan_10
Participant
0 Kudos

Hello,

does anyone have an ide how to create java mapping to create empty file on FTP?

Why this code always send NUL character = 1byte and not 0 byte as needed?

public void execute(InputStream in, OutputStream out) throws StreamTransformationException {

...

out = null;

...

}

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi

We can handle it in adapter itself , if the message is empty then we can handle it.

Regards

Chilla

milan_10
Participant
0 Kudos

But what does it mean that message is empty.? I think it means that the payload's size is 0. I thought that I could get it via java mapping and setting OutputStream = null. Then you could handle it in adapter, and set write empty file.

But even I set outputstream to null I get nul char in that stream and it has byte, so it's not empty any more!!! And I also have the requirement that the file have to be 0 byte.

Former Member
0 Kudos

Hi,

in your mapping after creating the file. it the sender side elements are not existed then no data will be stored ..

try to handle like this

Regards

Chilla

milan_10
Participant
0 Kudos

I'm not sure if I understant what you mean.

I of course first do the maping, then you send it to receiver.

VijayKonam
Active Contributor
0 Kudos

HI,

You might want to fill the OutputStream with an empty string "" rather than with a null. Not sure if this could be a solution, but you can definetly try this out.

Vijay

milan_10
Participant
0 Kudos

Hi,

I also try that of course, and the result was the same...

Thanks Milan

prateek
Active Contributor
0 Kudos

try 1 thing...

run ur code for some standalone file.

create a file at ur local harddisk and check out its size..

i had tried creating such a file using the code below....

it is creating a 0 byte file successfully.

public class TestCode {

public static void main(String ags[]){

try{

TransformerFactory tf = TransformerFactory.newInstance();

Transformer transform = tf.newTransformer();

FileOutputStream out;

out = new FileOutputStream("c:
OutTestCode.xml");

transform.transform(null, new StreamResult(out));

} catch (FileNotFoundException e1) {

e1.printStackTrace();

} catch (TransformerConfigurationException e) {

e.printStackTrace();

} catch (TransformerException e) {

e.printStackTrace();

}

}

}

Former Member
0 Kudos

Milan

You were trying to set the object "outputputstream" to null and not the value of the file

REgards

krishna

milan_10
Participant
0 Kudos

Hi,

yes all I need is to create empty file in file adpater. So I thought that when I set outputstrem to null, or to "".getBytes(), outputstreem will be empty, therefore file adapter will create empty 0byte file(SP19 file adpater feature, write empty files/ignore).

And as I said I always get NUL character, 1byte file. Bad bad bad...

Thanks.

milan_10
Participant
0 Kudos

Hi,

I think you didn't send it through XI. I did and the result is the same, file with size 1byte, nul character inside!

Thanks,

Milan