首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >android java实现缺陷..它们是否有文档记录?

android java实现缺陷..它们是否有文档记录?
EN

Stack Overflow用户
提问于 2011-07-17 12:29:14
回答 1查看 198关注 0票数 10

我使用运行android-7 (2.1)的模拟器和运行android-8 (2.2)的moto-defy来使用一个简单的android应用程序。

我遇到了一个有趣的问题,CSV解析应用程序在模拟器上失败了,但在defy和常规java应用程序(使用sun java)上成功了。

我追踪到了这个问题,原因是android-7的StringReader实现不支持负跳过操作:

Android-7:

代码语言:javascript
复制
/**
 * Skips {@code amount} characters in the source string. Subsequent calls of
 * {@code read} methods will not return these characters unless {@code
 * reset()} is used.
 *
 * @param ns
 *            the maximum number of characters to skip.
 * @return the number of characters actually skipped or 0 if {@code ns < 0}.
 * @throws IOException
 *             if this reader is closed.
 * @see #mark(int)
 * @see #markSupported()
 * @see #reset()
 */
@Override
public long skip(long ns) throws IOException {
    synchronized (lock) {
        if (isClosed()) {
            throw new IOException(Msg.getString("K0083")); //$NON-NLS-1$
        }
        if (ns <= 0) {
            return 0;
        }
        long skipped = 0;
        if (ns < this.count - pos) {
            pos = pos + (int) ns;
            skipped = ns;
        } else {
            skipped = this.count - pos;
            pos = this.count;
        }
        return skipped;
    }
}

J2SE 1.6:

代码语言:javascript
复制
/**
 * Skips the specified number of characters in the stream. Returns
 * the number of characters that were skipped.
 *
 * <p>The <code>ns</code> parameter may be negative, even though the
 * <code>skip</code> method of the {@link Reader} superclass throws
 * an exception in this case. Negative values of <code>ns</code> cause the
 * stream to skip backwards. Negative return values indicate a skip
 * backwards. It is not possible to skip backwards past the beginning of
 * the string.
 *
 * <p>If the entire string has been read or skipped, then this method has
 * no effect and always returns 0.
 *
 * @exception  IOException  If an I/O error occurs
 */
public long skip(long ns) throws IOException {
    synchronized (lock) {
        ensureOpen();
        if (next >= length)
            return 0;
        // Bound skip by beginning and end of the source
        long n = Math.min(length - next, ns);
        n = Math.max(-next, n);
        next += n;
        return n;
    }
}

因此,android版本不会向后跳过(解析器在某些情况下会使用它来预读字符),而是保持向前一个字符。

我的问题是,J2SE规范的各种不兼容性和变体是否有文档记录?如果没有,你们还遇到了什么其他问题。

谢谢你,p。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-07-17 13:43:40

一个值得关注的地方是Android问题跟踪器。

另一个值得关注的地方是Apache Harmony问题跟踪器。

诚然,使用问题跟踪器将涉及搜索,而不是浏览仔细分类的问题的网络。你可以把这看作是一个机会。

搜索和谐问题跟踪器显示,在不同的流类中,skip的行为存在一些问题。一个问题抱怨说,某些类的行为与javadoc不匹配……这是关闭的,因为它确实符合RI的行为,因此错误存在于javadoc中。

我的观点是,Sun / Oracle对这类事情承担了很大责任,因为他们拒绝以合理的条款将TCK授权给Apache Harmony项目。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6721928

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档