Results 1 to 6 of 6
  1. #1
    Proshitness is offline Member
    Join Date
    Oct 2011
    Posts
    28
    Rep Power
    0

    Default Getting all the bytes in a file

    When working on an encrypter I did this:
    Java Code:
    InputStream in = null;
    				byte[] data = null;
    				if (f != null) {
    					in = new FileInputStream(f);
    				} else {
    					in = new FileInputStream(iD.getText().toString());
    				}
    				KeyGenerator keygen = KeyGenerator.getInstance("AES");
    				SecretKey key = keygen.generateKey();
    				data = new byte[(int)f.length()];
    				in.read(data);
    				Cipher c = Cipher.getInstance("AES/ECB/PKCS5Padding");
    				c.init(mode, key);
    				byte[] eData = c.doFinal(data);
    				FileOutputStream t = new FileOutputStream(new File(getOutputFile()));
    				t.write(eData);
    				t.close();
    				System.out.println(eData);
    				if (in != null)
    					in.close();
    my problem is that the new line aren't there, I just get one line instead of the number of line that my file was, how can I make it so that It won't leave out the new lines?

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,574
    Rep Power
    23

    Default Re: Getting all the bytes in a file

    There are no "lines" in a file that is read as bytes. If you want lines, you need to read the file's contents as characters with a method that recognizes the lineend character as the end of a line.
    The lineend character is just another byte in the file's bytes.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Proshitness is offline Member
    Join Date
    Oct 2011
    Posts
    28
    Rep Power
    0

    Default Re: Getting all the bytes in a file

    ok, my problem with that is that with a cipher the "doFinal" method can only be used with a byte[] so if I do this instead will it work:
    lets say I give a file in the end of each line this char: '~' and in the code i look for that char in the line and if it is found I just add a '\n' in the output file
    will that work?

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,574
    Rep Power
    23

    Default Re: Getting all the bytes in a file

    What is in the output file? Is it text or bytes? If it's text for humans to read, then adding the '\n' should be OK.
    Why do you want to change the bytes in a file of bytes by adding a '\n'? Can the bytes in the file already have the '\n' character output by the doFinal() method?

    What is the problem you are trying to solve?
    Last edited by Norm; 06-15-2012 at 10:58 PM.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Proshitness is offline Member
    Join Date
    Oct 2011
    Posts
    28
    Rep Power
    0

    Default Re: Getting all the bytes in a file

    this is the problem:
    INPUT:

    -------- THE HPL ENGINE LOG ------------
    Engine build ID 20100819012504

    Creating Engine Modules
    --------------------------------------------------------
    Creating graphics module
    Creating system module
    Creating resource module
    Creating input module
    Creating sound module
    Creating physics module
    Creating ai module
    Creating gui module
    Creating generate module
    Creating haptic module
    Creating scene module
    --------------------------------------------------------

    Initializing Resources Module
    --------------------------------------------------------
    Creating loader handlers
    Creating resource managers
    Adding loaders to handlers
    --------------------------------------------------------

    Initializing Graphics Module
    --------------------------------------------------------
    --------------------------------------------------------

    Initializing Sound Module
    --------------------------------------------------------
    Initializing OpenAL
    Available OpenAL devices:
    0. Generic Software on AMD HDMI Output (2- AMD High Definition Audio Device)(OpenAL default)
    Trying to open device 'Generic Software on AMD HDMI Output (2- AMD High Definition Audio Device)'... Success!
    Number of mono sources: 32
    Streaming setup: 2 Buffers x 524288 bytes each
    --------------------------------------------------------

    Initializing Game Module
    --------------------------------------------------------
    Adding engine updates
    Initializing script functions
    --------------------------------------------------------

    User Initialization
    --------------------------------------------------------
    --------------------------------------------------------

    Exiting Gui Module
    --------------------------------------------------------
    Deleting all sets
    Deleting all skins
    Deleting all gfx elements
    Deleting all materials
    --------------------------------------------------------

    Exiting Generate Module
    --------------------------------------------------------
    --------------------------------------------------------

    Exiting Scene Module
    --------------------------------------------------------
    --------------------------------------------------------

    Exiting Input Module
    --------------------------------------------------------
    --------------------------------------------------------

    Exiting Sound Module
    --------------------------------------------------------
    --------------------------------------------------------

    Exiting Graphics Module
    --------------------------------------------------------
    --------------------------------------------------------

    Exiting Resources Module
    --------------------------------------------------------
    Done with fonts
    Done with scripts
    Done with particles
    Done with sounds
    Done with meshes
    Done with materials
    Done with Gpu programs
    Done with images
    Destroyed all textures
    Done with sound entities
    Done with animations
    Done with ent files
    All resources deleted
    --------------------------------------------------------

    Exiting Physics Module
    --------------------------------------------------------
    --------------------------------------------------------

    Exiting System Module
    --------------------------------------------------------
    --------------------------------------------------------

    Deleting game setup provided by user
    - Deleting lowlevel stuff.
    Physics
    Sound
    Input
    Resources
    System
    Graphics
    Haptic
    HPL Exit was successful!


    OUTPUT:
    6םs1‎S"׳tOYD[l׀סֽ–J״~EoUVv‎ˆeט‹)u Ni–?Rֶlum״ˆ@ךֺֽRֶlum״ˆ@ךֺֽRֶlum״ˆ @ךֺֽׂעפ”~ ְ"־<B־שMסל\.א וkUג "•‡\גa€ƒׁ>וױטגMa'+aEY‘Z#^א†46אrֵ-i“€h†:„׃‘׳`bֳץ™ Bs™”/izףseuּ…-*’%.ֳRֶlum״ˆ@ךֺֽRֶlum״ˆ@ךֺֽRֶlum״ˆ@ ךֺֽאל‚Jzdֿ`-Uכֻ„rƒ:טI#]#ײװbֿRת{‏ףH׳–?A0$,e]4 ןֱƒ>YxQ8hg›r0=’י;Rֶlum״ˆ@ךֺֽRֶlu m״ˆ@ךֺֽRֶlum״ˆ@ךֺֽ#ױ›׳PF‚`WnRֶlu m״ˆ@ךֺֽRֶlum״ˆ@ךֺֽ׃aׂיׁ[uT6V–-s‏Jׁ*'7SH•אrןֽkֲ„Cא`)ח‹•ד<#@&, fmˆRף*Wה+ֶ‰‘פ——L!‰ ״ב׃5dS€?RYְ׳>s]/יֽEX־ֱ–B>Y=װ;RHםט&m—+צJ₪F‡9פump’m*yֱ D‏ׂ׃(ן–‘שסֳז*[ספEצ`VS.RVזiץSֹRֶlum״ˆ@ךֺֽRֶlum״ˆ@ך ֺֽRֶlum״ˆ@ךֺֽ׃?sg)ִCp־Q<ת2ֲo,5 ‚B#ױ›׳PF‚`WnRֶlum״ˆ@ךֺֽRֶlum״ˆ@ךֺֽ םf…ְֳ9Dl9•Rֶlum״ˆ@ךֺֽRֶlum״ˆ@ךֺֽRֶ lum״ˆ@ךֺֽ @=5›וU ן~„C^ַo<ל׀ֶOYךֿL
    {ַZN[0ְ#ױ›׳PF‚`WnRֶlum״ˆ@ךֺֽRֶlum״ˆ@ךֺ ֽםf…ְֳ9Dl9•Rֶlum״ˆ@ךֺֽRֶlum״ˆ@ךֺֽ Rֶlum״ˆ@ךֺֽ=Aײ@Uֱ|דײ@Rֶlum״ˆ@ךֺֽRֶ lum״ˆ@ךֺֽׂM1ָױלXֺERֶlum״ˆ@ךֺֽRֶl um״ˆ@ךֺֽRֶlum״ˆ@ךֺֽ‹)u Ni–?Rֶlum״ˆ@ךֺֽRֶlum״ˆ@ךֺֽRֶlum״ˆ @ךֺֽ/^*(*-ס!*כRֶlum״ˆ@ךֺֽRֶlum״ˆ@ךֺֽל5pH₪–ַ /חIx“w>Vקֲ &N ־54H}ע-DIwׂךHO“YוB“גA7 /זI'}״
    סװpƒU₪‰nI.93ד_)=[ש ֻB:_)•׳ספgדהCS‰KQ/חw0A0אRtIנc‘.CpױRֶlum״ˆ@ךֺֽRֶlum״ˆ@ך ֺֽRֶlum״ˆ@ךֺֽWF@gPo“ֲ}פI="ˆחƒ_ֶ aRֶlum״ˆ@ךֺֽRֶlum״ˆ@ךֺֽRֶlum״ˆ@ךֺֽן רֳOG#ׁגִ…;ֶּFN׀P]—•=‏eRֶlum״ˆ@ךֺֽRֶlum״ˆ@ךֺֽ…אSS?װ ֺHךiנפטFV:2vכfyVG)1עו>kM™*WsֿGYן>cֲ| ץץ iTWכ'ֱָ•yu(ֽ ™~NEץ!;d’s &‘–&9
    First off you can see its not divided to a couple of line like the input is, and that is a problem for me.. =\

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,574
    Rep Power
    23

    Default Re: Getting all the bytes in a file

    Of course the encrypted file does not have "lines". All the bytes in the file including the lineend characters were encrypted.
    that is a problem for me
    Explain why that is a problem.

    Does the encrypted file have any lineend characters in it?
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. How to write bytes to text file?
    By fatabass in forum New To Java
    Replies: 10
    Last Post: 09-18-2012, 07:46 PM
  2. Why can't I read all the bytes from a text file ?
    By fatabass in forum New To Java
    Replies: 7
    Last Post: 01-16-2012, 09:17 PM
  3. Saving an array of bytes to a file
    By salmontres in forum New To Java
    Replies: 2
    Last Post: 12-13-2011, 01:17 AM
  4. Replies: 7
    Last Post: 10-28-2008, 01:41 PM
  5. DES algorithm (Read and Write bytes to file)
    By JoaoPe in forum Advanced Java
    Replies: 6
    Last Post: 07-29-2008, 03:46 PM

Posting Permissions

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