Results 1 to 6 of 6
Thread: Getting all the bytes in a file
- 06-15-2012, 08:54 PM #1
Member
- Join Date
- Oct 2011
- Posts
- 28
- Rep Power
- 0
Getting all the bytes in a file
When working on an encrypter I did this:
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?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();
- 06-15-2012, 10:38 PM #2
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.
- 06-15-2012, 10:46 PM #3
Member
- Join Date
- Oct 2011
- Posts
- 28
- Rep Power
- 0
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?
- 06-15-2012, 10:56 PM #4
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.
- 06-15-2012, 11:12 PM #5
Member
- Join Date
- Oct 2011
- Posts
- 28
- Rep Power
- 0
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םs1S"׳tOYD[l׀סֽ–J״~EoUVvˆeט‹)uNi–?Rֶlum״ˆ@ךֺֽRֶlum״ˆ@ךֺֽRֶlum״ˆ @ךֺֽׂעפ”~ְ"־<B־שMסל\.אוkUג "•‡\גa€ƒׁ>וױטגMa'+aEY‘Z#^א†46אrֵ-i“€h†:„׃‘׳`bֳץ™ Bs™”/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–-sJׁ*'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״ˆ@ךֺֽ‹)uNi–?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״ˆ@ךֺֽWF@gPo“ֲ}פI="ˆחƒ_ֶ aRֶlum״ˆ@ךֺֽRֶlum״ˆ@ךֺֽRֶlum״ˆ@ךֺֽן רֳOG#ׁגִ…;ֶּFN׀P]—•=eRֶlum״ˆ@ךֺֽRֶlum״ˆ@ךֺֽ…אSS?װ ֺHךiנפטFV:2vכfyVG)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.. =\
- 06-15-2012, 11:17 PM #6
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.
Explain why that is a problem.that is a problem for me
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
-
How to write bytes to text file?
By fatabass in forum New To JavaReplies: 10Last Post: 09-18-2012, 07:46 PM -
Why can't I read all the bytes from a text file ?
By fatabass in forum New To JavaReplies: 7Last Post: 01-16-2012, 09:17 PM -
Saving an array of bytes to a file
By salmontres in forum New To JavaReplies: 2Last Post: 12-13-2011, 01:17 AM -
How can you get the exact size of a file in bytes.
By J-Live in forum New To JavaReplies: 7Last Post: 10-28-2008, 01:41 PM -
DES algorithm (Read and Write bytes to file)
By JoaoPe in forum Advanced JavaReplies: 6Last Post: 07-29-2008, 03:46 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks