Java binding - BaseXClient.receive and BaseXClient.execute methods
Tuesday, 4 January 2011 · 7 messages
FE
Fabrice Etanchaud4 Jan 2011 14:36 #
Dear all at dbis, best greetings for the new year !
in the java binding class 'BaseXClient',
is there any reason not to add UTF-8 encoding when transforming outputstream into string ?
String receive() throws IOException {
final ByteArrayOutputStream os = new ByteArrayOutputStream();
receive(os);
return os.toString("UTF-8");
// return os.toString();
}
public String execute(final String cmd) throws IOException {final OutputStream os = new ByteArrayOutputStream();
execute(cmd, os);
return os.toString("UTF-8");
// return os.toString();
}
In which encoding is BaseX data internally stored, and then restituted ?
best regards,
Fabrice ETANCHAUD
AW
Andreas Weiler4 Jan 2011 14:45 #
Dear Fabrice,
the whole client-server communication is in UTF-8 so the strings havn't to be converted.
Kind regards,
Andreas
Quoted text · Fabrice Etanchaud · 43 lines
Am 04.01.11 14:36, schrieb Fabrice Etanchaud: > Dear all at dbis, best greetings for the new year ! > in the java binding class 'BaseXClient', > is there any reason not to add UTF-8 encoding when transforming > outputstream into string ? > > String receive() *throws*IOException { > > *final*ByteArrayOutputStream os = *new*ByteArrayOutputStream(); > > receive(os); > > *return*os.toString("UTF-8"); > > *// return*os.toString(); > > } > > *public*String execute(*final*String cmd) *throws*IOException { > > *final*OutputStream os = *new*ByteArrayOutputStream(); > > execute(cmd, os); > > ** > > **return*os.toString("UTF-8");* > > **// return*os.toString();* > > } > > In which encoding is BaseX data internally stored, and then restituted ? > > best regards, > > Fabrice ETANCHAUD > > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
LW
Leonard Wörteler4 Jan 2011 14:54 #
Hi,
Quoted text · Andreas Weiler · 3 lines
Am 04.01.2011 14:45, schrieb Andreas Weiler: > the whole client-server communication is in UTF-8 so the strings > havn't to be converted.
I think there can be problems if the default encoding isn't set to UTF-8 in the JVM, which is the case for Windows outside of Eclipse, AFAIK (CP-1252 there). Then the String would be decoded to Mojibake.
@Andi: Do you think adding the encoding would cause any problems?
Cheers, Leo
FE
Dear Andreas,
Thank you for you fast reply !
In my case, I get everything but readable text (Russian data), because my platform's default character encoding is 'windows-1252' and according the ByteArrayOutputStream API documentation :
toString
public String
<http://download.oracle.com/javase/1.5.0/docs/api/java/lang/String.html>
toString() Converts the buffer's contents into a string, translating bytes into characters according to the platform's default character encoding.
Overrides:
toString
<http://download.oracle.com/javase/1.5.0/docs/api/java/lang/Object.html# toString%28%29> in class Object
<http://download.oracle.com/javase/1.5.0/docs/api/java/lang/Object.html>
Returns:
String translated from the buffer's contents.
Since:
JDK1.1
So I had to force UTF-8 conversion using toString("UTF-8") in the receive and execute methods...
This could be a problem for others users.
Thank you for your great great job,
XML files' nightmare is other for me, thanks to BaseX !
Best regards
Fabrice
Quoted text · Andreas Weiler · 36 lines
From: Andreas Weiler [mailto:andreas.weiler at uni-konstanz.de] Sent: mardi 4 janvier 2011 14:46 To: Fabrice Etanchaud Cc: basex-talk at mailman.uni-konstanz.de Subject: Re: [basex-talk] Java binding - BaseXClient.receive and BaseXClient.execute methods Dear Fabrice, the whole client-server communication is in UTF-8 so the strings havn't to be converted. Kind regards, Andreas Am 04.01.11 14:36, schrieb Fabrice Etanchaud: Dear all at dbis, best greetings for the new year ! in the java binding class 'BaseXClient', is there any reason not to add UTF-8 encoding when transforming outputstream into string ? String receive() throws IOException { final ByteArrayOutputStream os = new ByteArrayOutputStream(); receive(os); return os.toString("UTF-8"); // return os.toString(); } public String execute(final String cmd) throws IOException { final OutputStream os = new ByteArrayOutputStream(); execute(cmd, os); return os.toString("UTF-8"); // return os.toString(); } In which encoding is BaseX data internally stored, and then restituted ? best regards, Fabrice ETANCHAUD _______________________________________________ BaseX-Talk mailing list BaseX-Talk at mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
AW
Andreas Weiler4 Jan 2011 15:07 #
Hi Fabrice,
im glad i could help, the bindings are just for standard use cases, so they can help people using the client-server architecture. Special cases need special modifications, as your case shows.
Kind regards,
Andreas
Quoted text · Fabrice Etanchaud · 93 lines
Am 04.01.11 15:00, schrieb Fabrice Etanchaud: > Dear Andreas, > Thank you for you fast reply ! > In my case, I get everything but readable text (Russian data), > because my platform's default character encoding is 'windows-1252' > and according the ByteArrayOutputStream API documentation : > > > toString > > publicString <http://download.oracle.com/javase/1.5.0/docs/api/java/lang/String.html> *toString*() > > Converts the buffer's contents into a string, translating bytes > into characters according to the platform's default character > encoding. > > *Overrides:* > |toString > <http://download.oracle.com/javase/1.5.0/docs/api/java/lang/Object.html#toString%28%29>| > in class |Object > <http://download.oracle.com/javase/1.5.0/docs/api/java/lang/Object.html>| > > *Returns:* > String translated from the buffer's contents. > *Since:* > JDK1.1 > > So I had to force UTF-8 conversion using toString("UTF-8") in the > receive and execute methods... > This could be a problem for others users. > Thank you for your great great job, > XML files' nightmare is other for me, thanks to BaseX ! > Best regards > Fabrice > > ------------------------------------------------------------------------ > *From:* Andreas Weiler [mailto:andreas.weiler at uni-konstanz.de] > *Sent:* mardi 4 janvier 2011 14:46 > *To:* Fabrice Etanchaud > *Cc:* basex-talk at mailman.uni-konstanz.de > *Subject:* Re: [basex-talk] Java binding - BaseXClient.receive and > BaseXClient.execute methods > > Dear Fabrice, > > the whole client-server communication is in UTF-8 so the strings > havn't to be converted. > > Kind regards, > Andreas > > Am 04.01.11 14:36, schrieb Fabrice Etanchaud: >> Dear all at dbis, best greetings for the new year ! >> in the java binding class 'BaseXClient', >> is there any reason not to add UTF-8 encoding when transforming >> outputstream into string ? >> >> String receive() *throws*IOException { >> >> *final*ByteArrayOutputStream os = *new*ByteArrayOutputStream(); >> >> receive(os); >> >> *return*os.toString("UTF-8"); >> >> *// return*os.toString(); >> >> } >> >> *public*String execute(*final*String cmd) *throws*IOException { >> >> *final*OutputStream os = *new*ByteArrayOutputStream(); >> >> execute(cmd, os); >> >> **return*os.toString("UTF-8");* >> >> **// return*os.toString();* >> >> } >> >> In which encoding is BaseX data internally stored, and then restituted ? >> >> best regards, >> >> Fabrice ETANCHAUD >> >> >> _______________________________________________ >> BaseX-Talk mailing list >> BaseX-Talk at mailman.uni-konstanz.de >> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >
FE
Fabrice Etanchaud4 Jan 2011 15:11 #
Dear Andreas,
Do you recommend using XQJ or XMLDB APIs instead of bindings ?
best regards
Quoted text · Andreas Weiler · 80 lines
From: Andreas Weiler [mailto:andreas.weiler at uni-konstanz.de] Sent: mardi 4 janvier 2011 15:08 To: Fabrice Etanchaud Cc: basex-talk at mailman.uni-konstanz.de Subject: Re: [basex-talk] Java binding - BaseXClient.receive and BaseXClient.execute methods Hi Fabrice, im glad i could help, the bindings are just for standard use cases, so they can help people using the client-server architecture. Special cases need special modifications, as your case shows. Kind regards, Andreas Am 04.01.11 15:00, schrieb Fabrice Etanchaud: Dear Andreas, Thank you for you fast reply ! In my case, I get everything but readable text (Russian data), because my platform's default character encoding is 'windows-1252' and according the ByteArrayOutputStream API documentation : toString public String <http://download.oracle.com/javase/1.5.0/docs/api/java/lang/String.html> toString() Converts the buffer's contents into a string, translating bytes into characters according to the platform's default character encoding. Overrides: toString <http://download.oracle.com/javase/1.5.0/docs/api/java/lang/Object.html# toString%28%29> in class Object <http://download.oracle.com/javase/1.5.0/docs/api/java/lang/Object.html> Returns: String translated from the buffer's contents. Since: JDK1.1 So I had to force UTF-8 conversion using toString("UTF-8") in the receive and execute methods... This could be a problem for others users. Thank you for your great great job, XML files' nightmare is other for me, thanks to BaseX ! Best regards Fabrice From: Andreas Weiler [mailto:andreas.weiler at uni-konstanz.de] Sent: mardi 4 janvier 2011 14:46 To: Fabrice Etanchaud Cc: basex-talk at mailman.uni-konstanz.de Subject: Re: [basex-talk] Java binding - BaseXClient.receive and BaseXClient.execute methods Dear Fabrice, the whole client-server communication is in UTF-8 so the strings havn't to be converted. Kind regards, Andreas Am 04.01.11 14:36, schrieb Fabrice Etanchaud: Dear all at dbis, best greetings for the new year ! in the java binding class 'BaseXClient', is there any reason not to add UTF-8 encoding when transforming outputstream into string ? String receive() throws IOException { final ByteArrayOutputStream os = new ByteArrayOutputStream(); receive(os); return os.toString("UTF-8"); // return os.toString(); } public String execute(final String cmd) throws IOException { final OutputStream os = new ByteArrayOutputStream(); execute(cmd, os); return os.toString("UTF-8"); // return os.toString(); } In which encoding is BaseX data internally stored, and then restituted ? best regards, Fabrice ETANCHAUD _______________________________________________ BaseX-Talk mailing list BaseX-Talk at mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
AW
Andreas Weiler4 Jan 2011 15:26 #
Dear Fabrice,
XQJ and XMLDB API arent working with the client-server architecture. They can just be used for local processes.
We always recommend to use our code base.
Kind regards,
Andreas
Quoted text · Fabrice Etanchaud · 117 lines
Am 04.01.11 15:11, schrieb Fabrice Etanchaud: > Dear Andreas, > Do you recommend using XQJ or XMLDB APIs instead of bindings ? > best regards > > ------------------------------------------------------------------------ > *From:* Andreas Weiler [mailto:andreas.weiler at uni-konstanz.de] > *Sent:* mardi 4 janvier 2011 15:08 > *To:* Fabrice Etanchaud > *Cc:* basex-talk at mailman.uni-konstanz.de > *Subject:* Re: [basex-talk] Java binding - BaseXClient.receive and > BaseXClient.execute methods > > Hi Fabrice, > > im glad i could help, the bindings are just for standard use cases, > so they can help people using the client-server architecture. > Special cases need special modifications, as your case shows. > > Kind regards, > Andreas > > Am 04.01.11 15:00, schrieb Fabrice Etanchaud: >> Dear Andreas, >> Thank you for you fast reply ! >> In my case, I get everything but readable text (Russian data), >> because my platform's default character encoding is 'windows-1252' >> and according the ByteArrayOutputStream API documentation : >> >> >> toString >> >> publicString <http://download.oracle.com/javase/1.5.0/docs/api/java/lang/String.html> *toString*() >> >> Converts the buffer's contents into a string, translating bytes >> into characters according to the platform's default character >> encoding. >> >> *Overrides:* >> |toString >> <http://download.oracle.com/javase/1.5.0/docs/api/java/lang/Object.html#toString%28%29>| >> in class |Object >> <http://download.oracle.com/javase/1.5.0/docs/api/java/lang/Object.html>| >> >> >> *Returns:* >> String translated from the buffer's contents. >> *Since:* >> JDK1.1 >> >> So I had to force UTF-8 conversion using toString("UTF-8") in the >> receive and execute methods... >> This could be a problem for others users. >> Thank you for your great great job, >> XML files' nightmare is other for me, thanks to BaseX ! >> Best regards >> Fabrice >> >> ------------------------------------------------------------------------ >> *From:* Andreas Weiler [mailto:andreas.weiler at uni-konstanz.de] >> *Sent:* mardi 4 janvier 2011 14:46 >> *To:* Fabrice Etanchaud >> *Cc:* basex-talk at mailman.uni-konstanz.de >> *Subject:* Re: [basex-talk] Java binding - BaseXClient.receive and >> BaseXClient.execute methods >> >> Dear Fabrice, >> >> the whole client-server communication is in UTF-8 so the strings >> havn't to be converted. >> >> Kind regards, >> Andreas >> >> Am 04.01.11 14:36, schrieb Fabrice Etanchaud: >>> Dear all at dbis, best greetings for the new year ! >>> in the java binding class 'BaseXClient', >>> is there any reason not to add UTF-8 encoding when transforming >>> outputstream into string ? >>> >>> String receive() *throws*IOException { >>> >>> *final*ByteArrayOutputStream os = *new*ByteArrayOutputStream(); >>> >>> receive(os); >>> >>> *return*os.toString("UTF-8"); >>> >>> *// return*os.toString(); >>> >>> } >>> >>> *public*String execute(*final*String cmd) *throws*IOException { >>> >>> *final*OutputStream os = *new*ByteArrayOutputStream(); >>> >>> execute(cmd, os); >>> >>> **return*os.toString("UTF-8");* >>> >>> **// return*os.toString();* >>> >>> } >>> >>> In which encoding is BaseX data internally stored, and then restituted ? >>> >>> best regards, >>> >>> Fabrice ETANCHAUD >>> >>> >>> _______________________________________________ >>> BaseX-Talk mailing list >>> BaseX-Talk at mailman.uni-konstanz.de >>> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >> >
Written for BaseX 6. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery