求证,一段开源项目上的源代码。

xmpp 2004-02-25 02:48:50
项目:apache上的jakarta下的commons-fileupload。
其中有一个类ThresholdingOutputStream.java
完整代码如下:
/*
* $Header: /home/cvs/jakarta-commons/fileupload/src/java/org/apache/commons/fileupload/ThresholdingOutputStream.java,v 1.3 2003/05/31 22:31:08 martinc Exp $
* $Revision: 1.3 $
* $Date: 2003/05/31 22:31:08 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
package org.apache.commons.fileupload;

import java.io.IOException;
import java.io.OutputStream;

public abstract class ThresholdingOutputStream
extends OutputStream
{
private int threshold;

private long written;

private boolean thresholdExceeded;

public ThresholdingOutputStream(int threshold)
{
this.threshold = threshold;
}

public void write(int b) throws IOException
{
checkThreshold(1);
getStream().write(b);
written++;
}

public void write(byte b[]) throws IOException
{
checkThreshold(b.length);
getStream().write(b);
written += b.length;
}

public void write(byte b[], int off, int len) throws IOException
{
checkThreshold(len);
getStream().write(b, off, len);
written += len;
}

public void flush() throws IOException
{
getStream().flush();
}

public void close() throws IOException
{
try
{
flush();
}
catch (IOException ignored)
{
// ignore
}
getStream().close();
}

public int getThreshold()
{
return threshold;
}

public long getByteCount()
{
return written;
}

public boolean isThresholdExceeded()
{
return (written > threshold);
}

protected void checkThreshold(int count) throws IOException
{
if (!thresholdExceeded && (written + count > threshold))
{
thresholdReached();
thresholdExceeded = true;
}
}

protected abstract OutputStream getStream() throws IOException;

protected abstract void thresholdReached() throws IOException;
}
其中的checkThreshold(int count)方法应该有问题的啊。因为thresholdExceeded属性还没有初始化啊。
...全文
28 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧