本文整理汇总了Java中org.apache.commons.net.io.CopyStreamListener类的典型用法代码示例。如果您正苦于以下问题:Java CopyStreamListener类的具体用法?Java CopyStreamListener怎么用?Java CopyStreamListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CopyStreamListener类属于org.apache.commons.net.io包,在下文中一共展示了CopyStreamListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: __mergeListeners
import org.apache.commons.net.io.CopyStreamListener; //导入依赖的package包/类
/**
* Merge two copystream listeners, either or both of which may be null.
*
* @param local the listener used by this class, may be null
* @return a merged listener or a single listener or null
* @since 3.0
*/
private CopyStreamListener __mergeListeners(CopyStreamListener local) {
if (local == null) {
return __copyStreamListener;
}
if (__copyStreamListener == null) {
return local;
}
// Both are non-null
CopyStreamAdapter merged = new CopyStreamAdapter();
merged.addCopyStreamListener(local);
merged.addCopyStreamListener(__copyStreamListener);
return merged;
}
示例2: __mergeListeners
import org.apache.commons.net.io.CopyStreamListener; //导入依赖的package包/类
private CopyStreamListener __mergeListeners(CopyStreamListener local) {
if(local == null) {
return this.__copyStreamListener;
} else if(this.__copyStreamListener == null) {
return local;
} else {
CopyStreamAdapter merged = new CopyStreamAdapter();
merged.addCopyStreamListener(local);
merged.addCopyStreamListener(this.__copyStreamListener);
return merged;
}
}
示例3: copyStream
import org.apache.commons.net.io.CopyStreamListener; //导入依赖的package包/类
public static final long copyStream(InputStream source, OutputStream dest, int bufferSize, long streamSize, CopyStreamListener listener, boolean flush) throws CopyStreamException {
byte[] buffer = new byte[bufferSize];
long total = 0L;
try {
int bytes;
while((bytes = source.read(buffer)) != -1) {
if(bytes == 0) {
bytes = source.read();
if(bytes < 0) {
break;
}
dest.write(bytes);
if(flush) {
dest.flush();
}
++total;
if(listener != null) {
listener.bytesTransferred(total, 1, streamSize);
}
} else {
dest.write(buffer, 0, bytes);
if(flush) {
dest.flush();
}
total += (long)bytes;
if(listener != null) {
listener.bytesTransferred(total, bytes, streamSize);
}
}
}
return total;
} catch (IOException var12) {
throw new CopyStreamException("IOException caught while copying.", total, var12);
}
}
示例4: bytesTransferred
import org.apache.commons.net.io.CopyStreamListener; //导入依赖的package包/类
public void bytesTransferred(CopyStreamEvent event) {
Iterator var3 = this.internalListeners.iterator();
while(var3.hasNext()) {
EventListener listener = (EventListener)var3.next();
((CopyStreamListener)listener).bytesTransferred(event);
}
}
示例5: __mergeListeners
import org.apache.commons.net.io.CopyStreamListener; //导入依赖的package包/类
/**
* Merge two copystream listeners, either or both of which may be null.
*
* @param local the listener used by this class, may be null
* @return a merged listener or a single listener or null
* @since 3.0
*/
private CopyStreamListener __mergeListeners(CopyStreamListener local) {
if (local == null) {
return __copyStreamListener;
}
if (__copyStreamListener == null) {
return local;
}
// Both are non-null
CopyStreamAdapter merged = new CopyStreamAdapter();
merged.addCopyStreamListener(local);
merged.addCopyStreamListener(__copyStreamListener);
return merged;
}
示例6: setCopyStreamListener
import org.apache.commons.net.io.CopyStreamListener; //导入依赖的package包/类
public void setCopyStreamListener(CopyStreamListener listener) {
this.__copyStreamListener = listener;
}
示例7: getCopyStreamListener
import org.apache.commons.net.io.CopyStreamListener; //导入依赖的package包/类
public CopyStreamListener getCopyStreamListener() {
return this.__copyStreamListener;
}
示例8: copyReader
import org.apache.commons.net.io.CopyStreamListener; //导入依赖的package包/类
public static final long copyReader(Reader source, Writer dest, int bufferSize, long streamSize, CopyStreamListener listener) throws CopyStreamException {
char[] buffer = new char[bufferSize];
long total = 0L;
try {
int chars;
while((chars = source.read(buffer)) != -1) {
if(chars == 0) {
chars = source.read();
if(chars < 0) {
break;
}
dest.write(chars);
dest.flush();
++total;
if(listener != null) {
listener.bytesTransferred(total, chars, streamSize);
}
} else {
dest.write(buffer, 0, chars);
dest.flush();
total += (long)chars;
if(listener != null) {
listener.bytesTransferred(total, chars, streamSize);
}
}
}
return total;
} catch (IOException var11) {
throw new CopyStreamException("IOException caught while copying.", total, var11);
}
}
示例9: addCopyStreamListener
import org.apache.commons.net.io.CopyStreamListener; //导入依赖的package包/类
public void addCopyStreamListener(CopyStreamListener listener) {
this.internalListeners.addListener(listener);
}
示例10: removeCopyStreamListener
import org.apache.commons.net.io.CopyStreamListener; //导入依赖的package包/类
public void removeCopyStreamListener(CopyStreamListener listener) {
this.internalListeners.removeListener(listener);
}
示例11: getEntityMedia
import org.apache.commons.net.io.CopyStreamListener; //导入依赖的package包/类
@Override
public ODataResponse getEntityMedia (ODataSingleProcessor processor)
throws ODataException
{
initNode ();
if (hasStream ())
{
try
{
User u = Security.getCurrentUser();
String user_name = (u == null ? null : u.getUsername ());
InputStream is = new BufferedInputStream (getStream());
RegulatedInputStream.Builder builder =
new RegulatedInputStream.Builder (is, TrafficDirection.OUTBOUND);
builder.userName (user_name);
CopyStreamAdapter adapter = new CopyStreamAdapter ();
CopyStreamListener recorder = new DownloadActionRecordListener (
this.getId (), this.getName (), u);
CopyStreamListener closer = new DownloadStreamCloserListener (is);
adapter.addCopyStreamListener (recorder);
adapter.addCopyStreamListener (closer);
builder.copyStreamListener (adapter);
if (getContentLength ()>0) builder.streamSize(getContentLength());
is = builder.build();
String etag = getName () + "-" + getContentLength ();
// A priori Node never change, so the lastModified should be as
// far as possible than today.
long last_modified = System.currentTimeMillis () - ONE_YEAR_MS;
// If node is not a data file, it cannot be downloaded and set to -1
// As a stream exists, this control is probably obsolete.
long content_length = getContentLength ()==0?-1:getContentLength ();
return MediaResponseBuilder.prepareMediaResponse(etag, getName(),
getContentType (), last_modified, content_length,
processor.getContext (), is);
}
catch (Exception e)
{
throw new ODataException (
"An exception occured while creating the stream for node " +
getName(), e);
}
}
else
{
throw new ODataException ("No stream for node " + getName ());
}
}
示例12: setCopyStreamListener
import org.apache.commons.net.io.CopyStreamListener; //导入依赖的package包/类
public void setCopyStreamListener(CopyStreamListener listener) {
delegate.setCopyStreamListener(listener);
}
示例13: getCopyStreamListener
import org.apache.commons.net.io.CopyStreamListener; //导入依赖的package包/类
public CopyStreamListener getCopyStreamListener() {
return delegate.getCopyStreamListener();
}
示例14: setCopyStreamListener
import org.apache.commons.net.io.CopyStreamListener; //导入依赖的package包/类
public void setCopyStreamListener(CopyStreamListener listener) {
this.delegate.setCopyStreamListener(listener);
}
示例15: getCopyStreamListener
import org.apache.commons.net.io.CopyStreamListener; //导入依赖的package包/类
public CopyStreamListener getCopyStreamListener() {
return this.delegate.getCopyStreamListener();
}