0

I receive data from a InputStream and I have a ASCII character 11 which is a vertical tab. I can see the vertical tab 11 in the debugger. As soon as I try to append that character to the StringBuilder it is appended and the length is increased.

However, the problem is that when the String is returned the ASCII character is lost but when doing stringBuilder.toString().toCharArray() the ASCII character 11 can be seen.

I need to see in the String the ASCII character 11.

public static void main(String[] args) {
     // Receive data from InputStream
     int read = inputStream.read();
     StringBuilder stringBuilder = new StringBuilder();
     stringBuilder.append((char) read); // /u000b is ' '
     stringBuilder.append("H");
     System.out.println(stringBuilder.toString()); // prints H
     char[] characters = stringBuilder.toString().toCharArray(); // length 2
}

How can this be achived?

EDIT:

I need to see the ASCII character in the original String in the debugger. For example:

public String getOriginalString() {
    return originalString;
}

public String process(String originalString) {
     return modifiedString;
}

EDIT:

public String buildMessage(InputStream inputStream) throws Exception {
    StringBuilder message = null;
    if(inputStream != null) {
        message = new StringBuilder();
        BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
        int byteRead = bufferedInputStream.read();
        while(byteRead != -1) {
            char value = (char) byteRead;
            message.append(value);
            // check how many bytes available
            if(bufferedInputStream.available() != 0) {
                byteRead = bufferedInputStream.read();
            }
            else {
                // to avoid blocking of data
                break;
            }
        }
    }
    char[] characters = message.toString().toCharArray(); // returns length 2
    return message.toString();
}

public static void main(String[] args) {
    String i = buildMessage(inputStream);
    char[] characters = i.toCharArray(); // ASCII characters lost
    StringBuilder stringBuilder = new StringBuider(i);
    char[] characters2 = stringBuilder.toString().toCharArray(); // ASCII characters lost
}
user3189663
  • 211
  • 4
  • 18
  • Post a minimal, but complete program showing the problem. – JB Nizet Apr 23 '14 at 11:51
  • That's not a complete program. I can't run it and reproduce the problem. Here's one, which of course does NOT reproduce the problem: https://gist.github.com/jnizet/11212992 – JB Nizet Apr 23 '14 at 12:17

2 Answers2

2

A vertical tab is white-space, so you can not "see it". What do you expect the visual appear of a vertical tab to be? The vertical tab ASCII character is a historical artefact, dating to the days to teletypes. It has has no generally accepted special meaning for VDUs and windoing systems displaying text.

Community
  • 1
  • 1
Raedwald
  • 46,613
  • 43
  • 151
  • 237
  • I don't want to see it. I need this String to be passed to another method that will contain the original data with ASCII characters so that further processing can be done. – user3189663 Apr 23 '14 at 11:40
  • 1
    @user3189663 And what makes you think that the string doesn't contain it? It does, since the length of the string is 2. – JB Nizet Apr 23 '14 at 11:43
  • Correct. The above is only code sample but when the method returns and when doing string.toString().toCharArray() the ASCII characters are lost. – user3189663 Apr 23 '14 at 11:45
1

The console that shows your output simply doesn't support that character, I guess. No way that it is not passed to stdout or that the resulting string doesn't contain your character.

Martijn Courteaux
  • 67,591
  • 47
  • 198
  • 287