Created
April 26, 2012 08:35
-
-
Save seratch/2497652 to your computer and use it in GitHub Desktop.
java.io.DataOutputStream 64KB limitation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io._ | |
| val bao = new ByteArrayOutputStream | |
| val dos = new DataOutputStream(bao) | |
| val chank64kMinus1 = new StringBuilder | |
| val limit = 1024 * 64 - 1 | |
| 1 to limit foreach { _ => chank64kMinus1.append("a") } | |
| dos.writeUTF(chank64kMinus1.toString) | |
| println(limit + " bytes is acceptable.") | |
| val chank64k = new StringBuilder | |
| 1 to (limit + 1) foreach { _ => chank64k.append("a") } | |
| try { | |
| dos.writeUTF(chank64k.toString) | |
| } catch { case e: UTFDataFormatException => | |
| e.printStackTrace | |
| /* | |
| java.io.UTFDataFormatException: encoded string too long: 65536 bytes | |
| at java.io.DataOutputStream.writeUTF(DataOutputStream.java:347) | |
| at java.io.DataOutputStream.writeUTF(DataOutputStream.java:306) | |
| at Main$$anon$1.<init>(dos_64kb_limit.scala:16) | |
| at Main$.main(java64kb_limit.scala:1) | |
| at Main.main(java64kb_limit.scala) | |
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) | |
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) | |
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) | |
| at java.lang.reflect.Method.invoke(Method.java:597) | |
| at scala.tools.nsc.util.ScalaClassLoader$$anonfun$run$1.apply(ScalaClassLoader.scala:78) | |
| at scala.tools.nsc.util.ScalaClassLoader$class.asContext(ScalaClassLoader.scala:24) | |
| at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.asContext(ScalaClassLoader.scala:88) | |
| at scala.tools.nsc.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:78) | |
| at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:101) | |
| at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:33) | |
| at scala.tools.nsc.ObjectRunner$.runAndCatch(ObjectRunner.scala:40) | |
| */ | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment