Android FileOutputStream.write:得到 java.io.IOException:数学结果无法表示
我在野外服务器错误日志中得到了那个“有趣的”异常。我的应用程序将异常和“wtf”错误发布到我的中央服务器,因此我没有太多信息到底发生了什么。我只知道它发生了,但我没有任何线索。
堆栈跟踪:
<代码> java.io.IOException:数学结果无法表示 在 org.apache.harmony.luni.platform.OSFileSystem.writeImpl(本机方法) 在 org.apache.harmony.luni.platform.OSFileSystem.write(OSFileSystem.java:129) 在 java.io.FileOutputStream.write(FileOutputStream.java:297) 在 net.jav.apps.romeolive.RomeoInterface.fetchBinaryToFile(RomeoInterface.java:299) 在 net.jav.apps.romeolive.HeartBeatService$_fetchPic.run(HeartBeatService.java:327) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561) 在 java.lang.Thread.run(Thread.java:1096)
代替 net.jav.apps.romeolive.RomeoInterface 的代码:
byte[] ret=fetchBinary(fullurl);
if (ret==null) return false;
try
{
FileOutputStream os=new FileOutputStream(getCacheFileName(type,fullurl));
os.write(ret, 0, ret.length);
“失败”行 #299 是 os.write()
fetchBinary(url ) 从 Web 服务器获取一些二进制文件(缩略图 jpg)并将其作为 byte[] 返回,如果未找到/错误则返回 NULL。
getCacheFileName(type,fullurl) 返回cacheDir() 加类型加上清理后的fullurl(删除斜杠,仅使用url 的本地部分)。
所以到底失败的是......尝试将现有的缩略图 jpg byte[] 写入 cacheDir() 中完美制作的文件名。
出现此异常的设备(到目前为止仅一次)是: GT-I9000@samsung/GT-I9000/GT-I9000/GT-I9000:2.2.1/FROYO/XXJPY:user/release-keys
有人有这个吗“数学结果无法表示”为 IOException? 我真的很想确定这一点;)Google 和 Stackoverflow 没有显示任何有用的甚至相关的内容。
多谢, 奥利弗
I got that "interesting" exception in my in-the-wild server errorlog. My app posts exceptions and "wtf"-errors to my central server, so I don't have much information what exactly happend. I just know THAT it happend, and I don't have any clue.
Stacktrace:
java.io.IOException: Math result not representable
at org.apache.harmony.luni.platform.OSFileSystem.writeImpl(Native Method)
at org.apache.harmony.luni.platform.OSFileSystem.write(OSFileSystem.java:129)
at java.io.FileOutputStream.write(FileOutputStream.java:297)
at net.jav.apps.romeolive.RomeoInterface.fetchBinaryToFile(RomeoInterface.java:299)
at net.jav.apps.romeolive.HeartBeatService$_fetchPic.run(HeartBeatService.java:327)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
at java.lang.Thread.run(Thread.java:1096)
The code in place of net.jav.apps.romeolive.RomeoInterface:
byte[] ret=fetchBinary(fullurl);
if (ret==null) return false;
try
{
FileOutputStream os=new FileOutputStream(getCacheFileName(type,fullurl));
os.write(ret, 0, ret.length);
The "failing" line #299 is the os.write()
fetchBinary(url) fetches some binary file (thumbnail jpg) from a web server and returns it as a byte[], or NULL if not found/error.
getCacheFileName(type,fullurl) returns the cacheDir() plus type plus the sanitized fullurl (removing slashes, only use the localpart of the url).
So what exactly fails, is... Trying to write the existing thumbnail jpg byte[] to a perfectly crafted filename in cacheDir().
The device where this exception showed up (ONCE only until now) is: GT-I9000@samsung/GT-I9000/GT-I9000/GT-I9000:2.2.1/FROYO/XXJPY:user/release-keys
Did anyone have this "Math result not representable" as IOException?
I'd really like to nail down that thing ;) Google and Stackoverflow didn't show up anything helpful or even related.
Thanks a lot,
Oliver
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我看来,这可能不是您代码中的错误,但我不能确定这一点。
字符串“数学结果无法表示”在 Google 搜索中显示为与 ERRNO 34 (ERANGE) 关联,该字符串也用字符串“数值结果超出范围”表示。
org.apache.harmony.luni.platform.OSFileSystem.writeImpl 的来源是:
因此写入期间的任何随机系统错误都会渗透备份Java 中作为 IOException,包括 ERANGE。但我不知道哪里可能发生范围错误; write(2) 手册页 未将 ERANGE 列为其可能的错误代码之一。
It doesn't seem to me like this could be a bug in your code, but I can't be sure of that.
The string "Math result not representable" shows up in Google searches as being associated with ERRNO 34 (ERANGE), which is also represented with the string "Numerical result out of range".
The source for org.apache.harmony.luni.platform.OSFileSystem.writeImpl is:
So any random system error during the write will percolate back up to Java as an IOException, including ERANGE. But I don't see where a range error could have happened; the man page for write(2) doesn't list ERANGE as one of its possible error codes.