You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@tika.apache.org by Bratislav Stojanovic <br...@gmail.com> on 2013/10/18 11:42:29 UTC
Fwd: Tika OSGi bundle does not produce UTF-8 output
Hi,
I've tried exactly the same code in two scenarios :
Tika tika = new Tika();
Metadata metadata = new Metadata();
Reader reader = tika.parse(new File("..."));
FileWriter fw = new FileWriter(new File("..."));
int data = reader.read();
StringBuilder sb = new StringBuilder();
while (data != -1){
char dataChar = (char) data;
sb.append(dataChar);
fw.write(dataChar);
data = reader.read();
}
When I put this code in a simple Java project with tika-app-1.4.jar as a
dependency, it
generates UTF-8 output (correct).
When I put this code inside a bundle with *tika-bundle* and *tika-core* as
dependencies and deploy it
inside karaf, it generates ANSI output (blah).
Both projects are managed with maven and Eclipse 4.2.
Do I have to additionaly set something or should I embed tika-app inside my
bundle (using
maven-bundle-plugin)?
I'm using Tika 1.4, Java 1.6.45, Win 7 x64 and karaf 2.3.3.
--
Bratislav Stojanovic, M.Sc.
Re: Tika OSGi bundle does not produce UTF-8 output
Posted by Bratislav Stojanovic <br...@gmail.com>.
It's working now :)
OutputStreamWriter does the job correctly, no need to set anything in karaf.
Thank you Uwe!
On Fri, Oct 18, 2013 at 11:57 AM, Uwe Schindler <uw...@thetaphi.de> wrote:
> Your code does not explicitly give the charsets when reading/writing
> files. Don’t use FileWriter to save the output, use new
> OutputStreamWriter(new FileOutputStream(“…”), “UTF-8”); (unfortunately
> FileWriter does not have the charset parameter, so you need to use
> OutputStreamWriter).****
>
> ** **
>
> The reason why you see a difference may be because karaf uses another
> default charset.****
>
> ** **
>
> -----****
>
> Uwe Schindler****
>
> H.-H.-Meier-Allee 63, D-28213 Bremen****
>
> http://www.thetaphi.de****
>
> eMail: uwe@thetaphi.de****
>
> ** **
>
> *From:* Bratislav Stojanovic [mailto:bratislav1983@gmail.com]
> *Sent:* Friday, October 18, 2013 11:42 AM
> *To:* user@tika.apache.org
> *Subject:* Fwd: Tika OSGi bundle does not produce UTF-8 output****
>
> ** **
>
> Hi,****
>
> ** **
>
> I've tried exactly the same code in two scenarios :****
>
> ** **
>
> Tika tika = new Tika();****
>
> Metadata metadata = new Metadata();****
>
> ** **
>
> Reader reader = tika.parse(new File("..."));****
>
> FileWriter fw = new FileWriter(new File("..."));****
>
> ** **
>
> int data = reader.read();****
>
> StringBuilder sb = new StringBuilder();****
>
> while (data != -1){****
>
> char dataChar = (char) data;****
>
> sb.append(dataChar);****
>
> fw.write(dataChar);****
>
> data = reader.read();****
>
> }****
>
> ** **
>
> When I put this code in a simple Java project with tika-app-1.4.jar as a
> dependency, it****
>
> generates UTF-8 output (correct).****
>
> When I put this code inside a bundle with *tika-bundle* and *tika-core*as dependencies and deploy it
> ****
>
> inside karaf, it generates ANSI output (blah).****
>
> Both projects are managed with maven and Eclipse 4.2.****
>
> ** **
>
> Do I have to additionaly set something or should I embed tika-app inside
> my bundle (using****
>
> maven-bundle-plugin)?****
>
> ** **
>
> I'm using Tika 1.4, Java 1.6.45, Win 7 x64 and karaf 2.3.3.****
>
> ** **
>
> ** **
>
> -- ****
>
> Bratislav Stojanovic, M.Sc.****
>
--
Bratislav Stojanovic, M.Sc.
Owner
*Cloudscraper Enterprise Search*
Skype: bratislav83
http://www.cloudscraper.ca
RE: Tika OSGi bundle does not produce UTF-8 output
Posted by Uwe Schindler <uw...@thetaphi.de>.
Your code does not explicitly give the charsets when reading/writing files. Don’t use FileWriter to save the output, use new OutputStreamWriter(new FileOutputStream(“…”), “UTF-8”); (unfortunately FileWriter does not have the charset parameter, so you need to use OutputStreamWriter).
The reason why you see a difference may be because karaf uses another default charset.
-----
Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen
http://www.thetaphi.de <http://www.thetaphi.de/>
eMail: uwe@thetaphi.de
From: Bratislav Stojanovic [mailto:bratislav1983@gmail.com]
Sent: Friday, October 18, 2013 11:42 AM
To: user@tika.apache.org
Subject: Fwd: Tika OSGi bundle does not produce UTF-8 output
Hi,
I've tried exactly the same code in two scenarios :
Tika tika = new Tika();
Metadata metadata = new Metadata();
Reader reader = tika.parse(new File("..."));
FileWriter fw = new FileWriter(new File("..."));
int data = reader.read();
StringBuilder sb = new StringBuilder();
while (data != -1){
char dataChar = (char) data;
sb.append(dataChar);
fw.write(dataChar);
data = reader.read();
}
When I put this code in a simple Java project with tika-app-1.4.jar as a dependency, it
generates UTF-8 output (correct).
When I put this code inside a bundle with tika-bundle and tika-core as dependencies and deploy it
inside karaf, it generates ANSI output (blah).
Both projects are managed with maven and Eclipse 4.2.
Do I have to additionaly set something or should I embed tika-app inside my bundle (using
maven-bundle-plugin)?
I'm using Tika 1.4, Java 1.6.45, Win 7 x64 and karaf 2.3.3.
--
Bratislav Stojanovic, M.Sc.