Sending both binary data and strings over the same stream

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tomPee
    New Member
    • Jun 2007
    • 21

    #16
    Hehe,

    Yeah, we figured we'd just go for the simplest policy of not supporting non-ASCII file names :P. It's not really a prerequisite either so we can easily skim on some on the difficulties there :).

    Kind Regards,
    Tom

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #17
      Originally posted by tomPee
      Hehe,

      Yeah, we figured we'd just go for the simplest policy of not supporting non-ASCII file names :P. It's not really a prerequisite either so we can easily skim on some on the difficulties there :).
      If you change your lines #8 and #14 to 'byte' instead of 'char' your entire class is prepared for Unicode names. The sender has to send the length of the file name measured in bytes of the encoded name. Your String constructor will take care of the decoding (if the encoding and decoding match).

      kind regards,

      Jos

      Comment

      • tomPee
        New Member
        • Jun 2007
        • 21

        #18
        Code:
          final char[] ch = new char[fileNameLength];
                     for (int i = 0; i < fileNameLength; i++) {
                         final int tmp = in.read();
                         if (tmp == -1) {
                             throw new IOException("End of stream prematurely ended.");
                         } else {
                             ch[i] = (char) tmp;
                         }
                    }
        One thing I'm wondering about then is... How do I determine how long the array of bytes for the filename has to be ? I'm assuming I'd just arbitrarily have to use a multiplier depending on the encoding used.

        But I'm glad to know it is actually that simple, when we've got the basics done, I'll pitch the idea to the other group members and see if we will implement it or not :). Cause Java isn't the problem with the encoding then, it'll depend on the C++ side then.
        Last edited by JosAH; Feb 15 '09, 12:00 PM. Reason: fixed the [code] ... [/code] tags

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #19
          Originally posted by tomPee
          One thing I'm wondering about then is... How do I determine how long the array of bytes for the filename has to be ?
          I assumed the sender sends the length of the file name (measured in bytes). According to your code you assume the same.

          kind regards,

          Jos

          Comment

          • devgupta01
            New Member
            • Jan 2008
            • 20

            #20
            Hiiiiiiiiiiiii i want know how to post a query

            Comment

            • tomPee
              New Member
              • Jun 2007
              • 21

              #21
              Originally posted by JosAH
              I assumed the sender sends the length of the file name (measured in bytes). According to your code you assume the same.

              kind regards,

              Jos
              Ah yeah, offcourse. My bad.
              Thanks :)

              Comment

              Working...