Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #28821 > unrolled thread

is that possible to include a small PNG file as part of Java class?

Started bywww <xsli2@yahoo.com>
First post2014-06-23 09:02 -0700
Last post2014-06-24 11:11 -0700
Articles 8 on this page of 28 — 11 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  is that possible to include a small PNG file as part of Java class? www <xsli2@yahoo.com> - 2014-06-23 09:02 -0700
    Re: is that possible to include a small PNG file as part of Java class? Martin Gregorie <martin@address-in-sig.invalid> - 2014-06-23 16:35 +0000
      Re: is that possible to include a small PNG file as part of Java class? Donkey Hottie <donkey@fredriksson.dy.fi> - 2014-06-24 15:54 +0300
        Re: is that possible to include a small PNG file as part of Java class? Jeff Higgins <jeff@invalid.invalid> - 2014-06-24 10:07 -0400
        Re: is that possible to include a small PNG file as part of Java class? Jeff Higgins <jeff@invalid.invalid> - 2014-06-24 10:49 -0400
        Re: is that possible to include a small PNG file as part of Java class? Roedy Green <see_website@mindprod.com.invalid> - 2014-06-25 01:25 -0700
    Re: is that possible to include a small PNG file as part of Java class? Marcel Müller <news.5.maazl@spamgourmet.org> - 2014-06-23 18:25 +0200
    Re: is that possible to include a small PNG file as part of Java class? Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-06-23 13:03 -0400
      Re: is that possible to include a small PNG file as part of Java class? Wanja Gayk <brixomatic@yahoo.com> - 2014-06-29 11:14 +0200
        Re: is that possible to include a small PNG file as part of Java class? Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-06-29 08:15 -0400
    Re: is that possible to include a small PNG file as part of Java class? markspace <markspace@nospam.nospam> - 2014-06-23 10:39 -0700
    Re: is that possible to include a small PNG file as part of Java class? Jeff Higgins <jeff@invalid.invalid> - 2014-06-23 15:04 -0400
      Re: is that possible to include a small PNG file as part of Java class? Roedy Green <see_website@mindprod.com.invalid> - 2014-06-25 01:34 -0700
    Re: is that possible to include a small PNG file as part of Java class? Joerg Meier <joergmmeier@arcor.de> - 2014-06-23 21:15 +0200
      Re: is that possible to include a small PNG file as part of Java class? Jeff Higgins <jeff@invalid.invalid> - 2014-06-23 15:46 -0400
        Re: is that possible to include a small PNG file as part of Java class? Joerg Meier <joergmmeier@arcor.de> - 2014-06-23 22:08 +0200
          Re: is that possible to include a small PNG file as part of Java class? Jeff Higgins <jeff@invalid.invalid> - 2014-06-23 16:19 -0400
            Re: is that possible to include a small PNG file as part of Java class? Joerg Meier <joergmmeier@arcor.de> - 2014-06-23 22:34 +0200
              Re: is that possible to include a small PNG file as part of Java class? Jeff Higgins <jeff@invalid.invalid> - 2014-06-23 16:43 -0400
                Re: is that possible to include a small PNG file as part of Java class? Joerg Meier <joergmmeier@arcor.de> - 2014-06-24 00:21 +0200
                  Re: is that possible to include a small PNG file as part of Java class? Jeff Higgins <jeff@invalid.invalid> - 2014-06-23 21:02 -0400
                    Re: is that possible to include a small PNG file as part of Java class? Jeff Higgins <jeff@invalid.invalid> - 2014-06-23 21:10 -0400
                      Re: is that possible to include a small PNG file as part of Java class? Jeff Higgins <jeff@invalid.invalid> - 2014-06-23 21:23 -0400
                      Re: is that possible to include a small PNG file as part of Java class? Jeff Higgins <jeff@invalid.invalid> - 2014-06-24 16:17 -0400
            Re: is that possible to include a small PNG file as part of Java class? Jeff Higgins <jeff@invalid.invalid> - 2014-06-23 16:33 -0400
          Re: is that possible to include a small PNG file as part of Java class? Jeff Higgins <jeff@invalid.invalid> - 2014-06-24 16:00 -0400
    Re: is that possible to include a small PNG file as part of Java class? Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-06-24 17:17 +0000
    Re: is that possible to include a small PNG file as part of Java class? Roedy Green <see_website@mindprod.com.invalid> - 2014-06-24 11:11 -0700

Page 2 of 2 — ← Prev page 1 [2]


#28835

FromJeff Higgins <jeff@invalid.invalid>
Date2014-06-23 21:02 -0400
Message-ID<loaj1p$t6b$1@dont-email.me>
In reply to#28834
On 06/23/2014 06:21 PM, Joerg Meier wrote:
> On Mon, 23 Jun 2014 16:43:28 -0400, Jeff Higgins wrote:
>
>> On 06/23/2014 04:34 PM, Joerg Meier wrote:
>>> I don't see how java.util.Base64 relates to my use of Apache Commons.
>> It doesn't.
>> It relates to:
>
>> String data[] = ("    String data = \"" +
>> DatatypeConverter.printBase64Binary(bytes) + "\";")
>>                   .split("(?<=\\G.{83})");
>>           StringBuilder output = new StringBuilder();
>>           output.append(data[0] + "\n");
>>           for (int i = 1; i < data.length; i++) {
>>               output.append("            + \"" + data[i] + "\"\n");
>>           }
>
>> vs
>
>> Base64.getMimeEncoder().encodeToString(src)
>
>> Sorry, just didn't want to bring the "H" word into the mix. :)
>
> Well now, let's be fair - it's:
>
> DatatypeConverter.printBase64Binary(bytes)
>
> vs
>
> Base64.getMimeEncoder().encodeToString(src)
>
> The rest is just formatting so one can copy and paste the output directly
> into a java source file.
>

OK.

System.out.println(
   "String iconData = \n\""
   + Base64.getMimeEncoder()
   .encodeToString(src)
   .replaceAll("\r\n", "\"\r\n+\"")
   + "\";");

Some may consider this horrid. :|

[toc] | [prev] | [next] | [standalone]


#28836

FromJeff Higgins <jeff@invalid.invalid>
Date2014-06-23 21:10 -0400
Message-ID<loajg9$vja$1@dont-email.me>
In reply to#28835
On 06/23/2014 09:02 PM, Jeff Higgins wrote:
> On 06/23/2014 06:21 PM, Joerg Meier wrote:

>> Well now, let's be fair - it's:
>>
>> DatatypeConverter.printBase64Binary(bytes)
>>
>> vs
>>
>> Base64.getMimeEncoder().encodeToString(src)
>>
>> The rest is just formatting so one can copy and paste the output directly
>> into a java source file.
>>
>
> OK.
>
> System.out.println(
>    "String iconData = \n\""
>    + Base64.getMimeEncoder()
>    .encodeToString(src)
>    .replaceAll("\r\n", "\"\r\n+\"")
>    + "\";");
>
> Some may consider this horrid. :|
>
Not to mention that my Eclipse IDE gives an Access Restriction warning
for DatatypeConverter.printBase64Binary(bytes).
Not sure what that's all about.

[toc] | [prev] | [next] | [standalone]


#28837

FromJeff Higgins <jeff@invalid.invalid>
Date2014-06-23 21:23 -0400
Message-ID<loak9j$3ki$1@dont-email.me>
In reply to#28836
On 06/23/2014 09:10 PM, Jeff Higgins wrote:

> Not sure what that's all about.

I guess using either of our codes one could
use an Ant task to generate a source file that
would not only contain the icon data but access
it with ImageIcon getMyIcon()! :-))

[toc] | [prev] | [next] | [standalone]


#28844

FromJeff Higgins <jeff@invalid.invalid>
Date2014-06-24 16:17 -0400
Message-ID<locmmu$uj5$1@dont-email.me>
In reply to#28836
On 06/23/2014 09:10 PM, Jeff Higgins wrote:

> Not to mention that my Eclipse IDE gives an Access Restriction warning
> for DatatypeConverter.printBase64Binary(bytes).
> Not sure what that's all about.
>
Somehow I managed to set my execution environment to CDC 1.0?
Which brings up another *potential* reason to prefer Base64
over DatatypeConverter. You are in a Java 8 small profile environment.

[toc] | [prev] | [next] | [standalone]


#28832

FromJeff Higgins <jeff@invalid.invalid>
Date2014-06-23 16:33 -0400
Message-ID<loa38p$n2v$1@dont-email.me>
In reply to#28830
On 06/23/2014 04:19 PM, Jeff Higgins wrote:

System.out.println(file.length() + "  " + str.length());
732  1000
for the above mentioned jws.png

[toc] | [prev] | [next] | [standalone]


#28843

FromJeff Higgins <jeff@invalid.invalid>
Date2014-06-24 16:00 -0400
Message-ID<loclnp$mro$1@dont-email.me>
In reply to#28829
On 06/23/2014 04:08 PM, Joerg Meier wrote:
>> JDK 8 has java.util.Base64, that will make your example different.
>
> Is there any reason to use that over the already existing DatatypeConverter
> .printBase64Binary ?
>
Actually, the examples I've posted down thread contain a potential bug.
In them I've used Base64.getMimeEncoder()* which uses the alphabet in
Table 1 of RFC 4648 and includes the plus and backslash characters
which depending how you use the Strings might cause problems.

Using Base64.getUrlEncoder() is likely safer, as it uses the alphabet
in Table 2, the so called "URL and Filename safe" Base 64 Alphabet.

Thus a potential reason to prefer Base64 over DatatypeConverter.

*my motivation was the auto line wrapping.

[toc] | [prev] | [next] | [standalone]


#28841

FromAndreas Leitgeb <avl@auth.logic.tuwien.ac.at>
Date2014-06-24 17:17 +0000
Message-ID<slrnlqjckl.bi9.avl@login.logic.tuwien.ac.at>
In reply to#28821
www <xsli2@yahoo.com> wrote:
> I have a simple Java class: Abc.java. The method within it needs to access a small PNG file(it's an icon picture). Right now, this picture file("abc.png") is located at nonsrc/icons/abc.png
> So this class is a bit pain. Abc.class won't work in the absence of abc.png. When I create an executable JAR, this is pain: always need to remember to include abc.png file inside it.

There are already a few helpful followups about
 - using base64 encoded strings to actually embed binary data
 - using ant to automate the handling of abc.png along with
      the class file

Adding to the second one, I want to point out that relying on
self-contained .class files is walking on rather thin ice.  If
a .java source file uses certain Java-features (anonymous classes,
or even just a switch over an enum), then it will compile into
Abc.class plus something like a Abc$1.class, and then you will
need both of them, anyway.  Merely picking the Abc.class and
delivering it somewhere will sooner or later bring you spurious
ClassNotFoundExceptions.

[toc] | [prev] | [next] | [standalone]


#28842

FromRoedy Green <see_website@mindprod.com.invalid>
Date2014-06-24 11:11 -0700
Message-ID<lpfjq990rrj011kqeb513g4js9nkgi9jc8@4ax.com>
In reply to#28821
On Mon, 23 Jun 2014 09:02:20 -0700 (PDT), www <xsli2@yahoo.com> wrote,
quoted or indirectly quoted someone who said :

>I am wondering if there is a way that I can "convert"
 abc.png into some sort of Java code and I can put it in Abc.java. So
Abc.class alone can perform the job, without the need of presence of
abc.png. Is that possible?

There is such a program called cramfull see
http://mindprod.com/jgloss/cramfull.html


I think the java language should invent a tighter link to resources so
that they can be automatically included.
-- 
Roedy Green Canadian Mind Products http://mindprod.com
Why program by hand in 5 days what you can spend
2 to 5 years of your life automating.
~ Terence Parr 1964-08-17

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.java.programmer


csiph-web