Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 265446

Summary: binary data on standard output corrupt when written to file
Product: [Eclipse Project] JDT Reporter: Georg Müller <georgmueller>
Component: DebugAssignee: JDT-Debug-Inbox <jdt-debug-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: major    
Priority: P3 CC: Olivier_Thomann
Version: 3.4.1   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard: stalebug
Attachments:
Description Flags
Test.java to reproduce the problem none

Description Georg Müller CLA 2009-02-19 07:58:18 EST
Build ID: M20080911-1700

Steps To Reproduce:
I have a program which generates binary data and writes it to stdout via System.out.write(byte[]). The program is thought to work in a pipe.
In the run configuration -> common, I specify to write content to a file.
This data should by as-is, but the data is interpreted as UTF-8 and each byte with highes bit set (> 127, in java -128...-1) is converted to a UTF-8 representation. I know that this beavoir can be changed by changing console encoding to latin1 or any other single-byte-encoding, but this is not the point.

The following program shows the error:

    public static void main(String[] args) {

        byte badByte = -1; // 0xFF
        byte b[] = new byte[] { badByte, 'A', 'B', 'C'};

        try {
            System.out.write(b);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

This program should generate the following output (in hex):
ff 41 42 43

But the output file contains this:
ef bf bd 41 42 43

Btw: Even if I set badByte to another negative value (-128...-1), the output is always
ef bf bd 41 42 43


Furthermore, it would be good to have the possibility to specify 3 diffent files for stdin, stdout and stderr.
Comment 1 Olivier Thomann CLA 2009-02-19 08:49:43 EST
Could you please provide a complete test case that exhibits the problem with a file?
Thanks. 
Comment 2 Georg Müller CLA 2009-02-19 09:20:52 EST
Created attachment 126164 [details]
Test.java to reproduce the problem

This is the file Test.java.

To reproduce the error:
1. Open Run Dialog for this App, then open the "Common" tab
2. Set Console Encoding to UTF-8 (if not already the case)
3. Enable writing to a file
4. Run Test
5. Open output file in a hex editor

To reproduce the wished behavior:

1. Set Console Encoding to e.g. ISO 8859-1 and rerun
or
2. Run "java Test > outfile" from command line and open outfile in a hex editor
Comment 3 Olivier Thomann CLA 2009-02-19 09:26:38 EST
Moving to JDT/Debug
Comment 4 Eclipse Genie CLA 2020-03-22 06:51:54 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.