Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Pasting a file into a Java String

Reply
Thread Tools

Pasting a file into a Java String

 
 
Anguel Stankov
Guest
Posts: n/a
 
      05-12-2004
Thanks Roedy! Very nice code, exactly what I needed


Roedy Green <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>. ..

> I think you just want a way of making binary data printable.
>
> see http://mindprod.com/jgloss/printable.html
> e.g. base64
> see http://mindprod.com/jgloss/base64.html
> i.e. armouring for transport:
> http://mindprod.com/jgloss/armouring.html
>
> If you want to take arbitrary text and convert it to a Java program
> with that text as a string literal see http://mindprod.com/quoter.html
> e.g. turns " to \" , \ to \\, nl to \n and wraps the whole thing in
> "...".

 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      05-13-2004
On 12 May 2004 13:32:45 -0700, http://www.velocityreviews.com/forums/(E-Mail Removed) (Anguel Stankov) wrote
or quoted :

>Thanks Roedy! Very nice code, exactly what I needed


Which of the four options I gave you was the one you wanted?

>
>Roedy Green <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>. ..
>
>> I think you just want a way of making binary data printable.
>>
>> see http://mindprod.com/jgloss/printable.html
>> e.g. base64
>> see http://mindprod.com/jgloss/base64.html
>> i.e. armouring for transport:
>> http://mindprod.com/jgloss/armouring.html
>>
>> If you want to take arbitrary text and convert it to a Java program
>> with that text as a string literal see http://mindprod.com/quoter.html
>> e.g. turns "



--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
 
 
 
Anguel Stankov
Guest
Posts: n/a
 
      05-13-2004
Hi Roedy!

Roedy Green <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>. ..

> Which of the four options I gave you was the one you wanted?


I chose the Base64.

Regards,
Anguel
 
Reply With Quote
 
Anguel Stankov
Guest
Posts: n/a
 
      05-13-2004
Hi Roedy!

Roedy Green <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>. ..

> I lost you when you said you needed a String. Why not a byte array?


First of all I have to put the code of the whole .class file into my
java app before compiling it. That is needed because during runtime I
don't have any filesystem on the ROM to read from, just my app.
Therefore I must be able to open a .class file in an editor and paste
the whole thing into my java app. The only possibility I can think of
is to paste it into a String. Do you know a way to paste it into a
byte array? If I could paste it into a byte array, then maybe I would
not need to convert it to base64 at all...

Regards,
Anguel
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      05-13-2004
On 13 May 2004 04:06:17 -0700, (E-Mail Removed) (Anguel Stankov) wrote
or quoted :

>First of all I have to put the code of the whole .class file into my
>java app before compiling it. That is needed because during runtime I
>don't have any filesystem on the ROM to read from, just my app.
>Therefore I must be able to open a .class file in an editor and paste
>the whole thing into my java app. The only possibility I can think of
>is to paste it into a String. Do you know a way to paste it into a
>byte array? If I could paste it into a byte array, then maybe I would
>not need to convert it to base64 at all..


So you are putting a base64 version of your class hard coded as a
string constant into ROM. At run time you will convert this back to
byte array and use a class loader to convert it to a live class?

Why not just burn the class file into ROM? It would be more compact?
It seems you are burning your container class into RAM an binary.

If you must do what you are doing, and ROM is tight, for $100US I
could cook up a variant of Base 64 which is about twice as compact.
Base64 presumes 8-bit rather than 16-bit printable output.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
Anguel Stankov
Guest
Posts: n/a
 
      05-14-2004
Hi!

Roedy Green <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>. ..

> So you are putting a base64 version of your class hard coded as a
> string constant into ROM. At run time you will convert this back to
> byte array and use a class loader to convert it to a live class?


Almost. I will write the byte array into a file in the filesystem
which is in RAM. From there I will serve the class (which is an
applet) using a mini HTTPServer. No class loader is needed.

> Why not just burn the class file into ROM? It would be more compact?
> It seems you are burning your container class into RAM an binary.


I would need to write assembler code to read and write from and to
flash ROM. I would have to know which ROM banks are free. If I do all
from Java it is easier to do it and to update the program.

> If you must do what you are doing, and ROM is tight, for $100US I
> could cook up a variant of Base 64 which is about twice as compact.
> Base64 presumes 8-bit rather than 16-bit printable output.


Thanks but I've got plenty of ROM - 2 MB Base64 will do it.

Regards,
Anguel
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      05-14-2004
On 14 May 2004 01:39:42 -0700, (E-Mail Removed) (Anguel Stankov) wrote
or quoted :

>> If you must do what you are doing, and ROM is tight, for $100US I
>> could cook up a variant of Base 64 which is about twice as compact.
>> Base64 presumes 8-bit rather than 16-bit printable output.

>
>Thanks but I've got plenty of ROM - 2 MB Base64 will do it.


you would think code like this

byte[] classimage = new byte[]{ 0x43, 0x41, 0x46, .... };
would produce a string of hex bytes in the class file, but it
generates a horribly bulky code, to construct the array. Each of
those items could be a method call, so the code generated is fully
general, rather than optimised for compile-time constants.


This is one area the JVM class file format needs an extension. you
need a way to efficiently encode arrays of constant bytes or mostly
constant bytes, ints etc.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Prevent pasting into custom textbox control. AjitGoel ASP .Net 2 04-17-2007 10:21 PM
pasting numpy array into bigger array TG Python 3 07-26-2006 04:32 PM
pasting xml data into an excel template =?Utf-8?B?Z2FuZXNoX2luZm9zeXM=?= ASP .Net 1 08-24-2005 07:50 PM
Pasting JTable content into the body of an email message Marc Van Laer Java 0 04-11-2005 04:13 PM
How to concatening/pasting multiple web pages into one browser window with FRAMESET ??? Wladimir Borsov HTML 0 08-28-2003 08:59 AM



Advertisments