Download txt file

Hi all,
I have a problem when I want to download a txt file from the server.

I have my data stored in a Label called “message”, using “Content_preformatted” to allow “\n” and “\t” in the label.
To download the file, the user must click on a “Save” button:

Button print = new Button("Save", new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {

            	StreamSource source = new MyStringSource("Un document",message.getCaption());
                String filename = "equivalence_list.txt";
                StreamResource resource = new StreamResource(source,filename, getApplication());
                
                resource.setMIMEType("application/txt");
                resource.getStream().setParameter("Content-Disposition","attachment; filename="+filename);
                
                getWindow().open(resource);
            }
        });

StringSource class is:

class MyStringSource implements StreamSource {
    String name; 
    String data = new String();
    
    public MyStringSource(String name, String data) 
    {
        this.name = name;
        this.data = data;
    }

	public InputStream getStream() {
		ByteArrayInputStream foStream = new ByteArrayInputStream(data.getBytes());
        
        try {
            return foStream;
        } catch (Exception e) 
        {
            e.printStackTrace();
        }
        return null;
	}
}

The problem I have is that if I show the label on my window it appears with line breaks, but when I click on the “Save button”, the file created appears without the line breaks.

It’s the first time I’m developing a download button, so I thing that I’m doing silly errors somewhere in the code, but I’m not able to figure out what I’m doing wrong.

Thank you all in advance!