• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Java encoding

 
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I have a file(contains special characters Greek) on the server and am reading that file line by line and saving it as a file in my local machine.

I used the below code for reading
in = new BufferedReader(new InputStreamReader(urlContent.openStream(), encodingType));

While writing whether I need to encode it again ? is it needed.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is needed if you want the file to be encoded in a different encoding than the platform default encoding (whatever that may be on your machine).
 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Server is Unix and client in Windows. While reading am using encoding the file and agin if I encode it with same then the file become old type as in the server rite ?.


After storing that file in windows and then sending it to printer as below.

File pdfFile = new File(arg);
is = new BufferedInputStream(new FileInputStream(pdfFile));
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(is, flavor, das);
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

While reading am using encoding the file and agin if I encode it with same then the file become old type as in the server rite ?.


The encoding will be the same if you use the same encoding, otherwise it will be different (maybe I'm missing what you're trying to say).

is = new BufferedInputStream(new FileInputStream(pdfFile));


Again, this will only work if the file has the platform default encoding. If you're storing the file with any other encoding, then you need to specify that encoding here.
 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ulf,

Please help me out, How to specify the encoding here. I mean in the below code.

InputStream is = new BufferedInputStream(new FileInputStream(pdfFile));

is it possible to use the encoding string in above line.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, I misremembered. For printing, not the platform default encoding is used, but US-ASCII. If the file uses a different encoding then you need to specify the charset as part of the MIME type in the DocFlavor. See its javadocs for more detail: javax.print.DocFlavor.
 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While writing the file I used UTF8 encoding and stored the file.

DocFlavor flavor = DocFlavor.INPUT_STREAM.TEXT_PLAIN_UTF_8;

If I use the above flavor I got

java.lang.IllegalArgumentException: text/plain; charset="utf-8"; class="java.io.InputStream" is an unsupported flavor
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Print API has methods somewhere that allow you to detect/list all supported flavors. You'll have to use one of the supported ones, obviously. Which ones those are will vary from machine to machine, as it depends on the installed printer drivers and printers.
 
Uh oh, we're definitely being carded. Here, show him this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic