Results 1 to 10 of 10
  1. #1
    fred cooper is offline Member
    Join Date
    Feb 2017
    Posts
    5
    Rep Power
    0

    Default I'm trying to create a string from a file that does not truncate

    Hello all,

    I'm trying to import a file (stream) into a modem to test some encode/decode functions. The method below works just fine inputting the source text file but the decoded output file is truncated to 128 characters. Data type BYTE is limited to a field count of 0-127, I wondered if that was part of the problem? Right now I'm using ASCII characters because a text file is easy to create but the program will eventually use non-ASCII characters, just bytes from a video file. For initial testing I need no limit on the source file size. I appreciate in advance any insight or suggestions.

    Best
    Fred

    public void testReadFile() throws InterruptedException, IOException {
    InputStream is = ClassLoader.getSystemResourceAsStream("BigTextFile .txt");
    byte[] input = IOUtils.toByteArray(is);
    mEncoder.appendData(input);
    mEncoder.flushSignal();

    Thread.sleep(1000);

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,209
    Rep Power
    12

    Default Re: I'm trying to create a string from a file that does not truncate

    I need more explanation. A byte can hold 8 bits so that provides a value from 0 - 255. Assuming your input file is create okay, then there must be a problem with the mEncoder class. It is difficult to offer assistance based on the information provided. Where did the encode/decode class come from?

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    19,952
    Rep Power
    31

    Default Re: I'm trying to create a string from a file that does not truncate

    I'm not sure what your problem is. A byte array can hold much more than 128 bytes.
    What is the data type BYTE that you are asking about? Did you mean byte? Java is case sensitive.
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    fred cooper is offline Member
    Join Date
    Feb 2017
    Posts
    5
    Rep Power
    0

    Default Re: I'm trying to create a string from a file that does not truncate

    Hi Norm,

    The problem is that the input data file is truncated somewhere in the process to 128 characters. The method I attached in my initial post inputs a text file, encodes it, prints it and then decodes it, prints it. The output from the decoder is truncated at 128 characters when it is much bigger.

  5. #5
    fred cooper is offline Member
    Join Date
    Feb 2017
    Posts
    5
    Rep Power
    0

    Default Re: I'm trying to create a string from a file that does not truncate

    It's possible since whats printed from the mEncoder is not ASCII and not readable. If it's chopped in the mEncoder it will be chopped in the mDecoder as well. I'm using the Android FSK Modem found on GitHub. I have them working but this data truncation is a problem.

    Best
    Fred

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    19,952
    Rep Power
    31

    Default Re: I'm trying to create a string from a file that does not truncate

    Java Code:
    byte[] input = IOUtils.toByteArray(is);
    What is the size of input after this statement is executed?
    What is the size of the BigTextFile.txt file?

    Where is the size of anything 128?
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,209
    Rep Power
    12

    Default Re: I'm trying to create a string from a file that does not truncate

    Is it possible that the mEncoder class is truncating the input because it senses a special character? Have you tried a different input stream, say all A's or or all B's to see if behaves differently? I am also assuming you read the API documentation.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  8. #8
    fred cooper is offline Member
    Join Date
    Feb 2017
    Posts
    5
    Rep Power
    0

    Default Re: I'm trying to create a string from a file that does not truncate

    Quote Originally Posted by Norm View Post
    Java Code:
    byte[] input = IOUtils.toByteArray(is);
    What is the size of input after this statement is executed?
    What is the size of the BigTextFile.txt file?

    Where is the size of anything 128?
    I don't know what the size of the array is because I only see the output from the mEncode and then mDecode. I can actually only read the decode which is the original text. The BigTextFile.txt is 5 courses of alphabet so A-Z 5 times. "V" on the last course is where it truncates. So "X,Y,Z" is stripped. "V" is the 127th character. So 0-127 for the max character count in a byte string. There is no character "0" so it quits at 127.

  9. #9
    fred cooper is offline Member
    Join Date
    Feb 2017
    Posts
    5
    Rep Power
    0

    Default Re: I'm trying to create a string from a file that does not truncate

    Quote Originally Posted by jim829 View Post
    Is it possible that the mEncoder class is truncating the input because it senses a special character? Have you tried a different input stream, say all A's or or all B's to see if behaves differently? I am also assuming you read the API documentation.

    Regards,
    Jim
    It's possible, I'll try some different Characters at the end and see what happens.

  10. #10
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,209
    Rep Power
    12

    Default Re: I'm trying to create a string from a file that does not truncate

    To see the size of any array foo simply print out foo.length().

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Truncate a double variable
    By ahmedsameha1 in forum New To Java
    Replies: 6
    Last Post: 01-14-2015, 08:08 PM
  2. Truncate out
    By cytotoxictcell in forum New To Java
    Replies: 3
    Last Post: 05-16-2012, 06:12 AM
  3. Replies: 3
    Last Post: 10-25-2011, 06:29 PM
  4. truncate a decimal number ?
    By hacikho in forum New To Java
    Replies: 5
    Last Post: 10-13-2010, 08:58 PM
  5. To truncate jump of line in jsp
    By Eric in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 06-09-2007, 03:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •