18691 1 10 129

Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4513909

By: bosbert

Hi all,

I'm implementing a portlet that will be used to upload text files from clients.
These files are encoded in a french window's based encoding with some special characters (eg: e a e ...).
These files are respecting a predefined format and I need to keep them strictly unchanged.
I'm using th Fileupload component to get these files to the server. This component returns me an array of Media objects.
Unfortunately, I really don't have the hand on these components and I'm not able to specify the encoding, which is, I think, defined by default as UTF-8.
Because of this, I'm facing a lot of issues like lost of information when trying to convert these files.

Does anybody have an idea on how could I turn around this ?

Thanks a lot

delete retag edit

2 Replies

18691 1 10 129

Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4514180

By: waterbottle

Hi,
After upload, you can access text by getReaderData( if Media.inMemory() if false) or getStringData( if Media.inMemory() is true).
You can set default upload character in zk.xml like below:
<zk>
<system-config>

the default value is UTF-8

/Dennis

saprudin2009
30

if(media.getContentType().startsWith("text/")){
if (media.inMemory()){
Files.copy(new File(path), media.getReaderData(), media.getStringData()); ---> UnsupportedEncodingException
}else{
BufferedWriter writer = new BufferedWriter(new java.io.FileWriter(
path));
}

}

But, its still error

java.io.UnsupportedEncodingException:
at sun.nio.cs.StreamEncoder.forOutputStreamWriter(StreamEncoder.java:42)

at java.io.OutputStreamWriter.<init>(OutputStreamWriter.java:83)
at org.zkoss.io.FileWriter.<init>(FileWriter.java:78)
at org.zkoss.io.Files.copy(Files.java:165)
at com.telkomsel.composer.TicketComposer.saveToDisk(TicketComposer.java:
287)
at com.telkomsel.composer.TicketComposer.onClick$btnUpload(TicketCompose r.java:265) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl. java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces sorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.zkoss.zk.ui.event.GenericEventListener.onEvent(GenericEventListen er.java:89) at org.zkoss.zk.ui.impl.EventProcessor.process0(EventProcessor.java:197) at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:141) at org.zkoss.zk.ui.impl.EventProcessingThreadImpl.process0(EventProcessi ngThreadImpl.java:493) at org.zkoss.zk.ui.impl.EventProcessingThreadImpl.sendEvent(EventProcess ingThreadImpl.java:123) at org.zkoss.zk.ui.event.Events.sendEvent(Events.java:293) at org.zkoss.zk.ui.event.Events.sendEvent(Events.java:303) at org.zkoss.zk.ui.AbstractComponent$ForwardListener.onEvent(AbstractCom
ponent.java:2308)
at org.zkoss.zk.ui.impl.EventProcessor.process0(EventProcessor.java:197)

at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:141)

[hide preview]