01: /*
02: * ====================================================================
03: * Copyright (c) 2004-2008 TMate Software Ltd. All rights reserved.
04: *
05: * This software is licensed as described in the file COPYING, which
06: * you should have received as part of this distribution. The terms
07: * are also available at http://svnkit.com/license.html
08: * If newer versions of this license are posted there, you may use a
09: * newer version instead, at your option.
10: * ====================================================================
11: */
12: package org.tmatesoft.svn.core.internal.wc;
13:
14: import java.io.FilterOutputStream;
15: import java.io.IOException;
16: import java.io.OutputStream;
17:
18: import org.tmatesoft.svn.core.ISVNCanceller;
19: import org.tmatesoft.svn.core.SVNCancelException;
20:
21: /**
22: * @version 1.1.1
23: * @author TMate Software Ltd.
24: */
25: public class SVNCancellableOutputStream extends FilterOutputStream {
26:
27: private ISVNCanceller myEventHandler;
28:
29: public SVNCancellableOutputStream(OutputStream out,
30: ISVNCanceller eventHandler) {
31: super (out == null ? SVNFileUtil.DUMMY_OUT : out);
32: myEventHandler = eventHandler;
33: }
34:
35: public void write(byte[] b, int off, int len) throws IOException {
36: if (myEventHandler != null) {
37: try {
38: myEventHandler.checkCancelled();
39: } catch (final SVNCancelException e) {
40: throw new IOCancelException(e.getMessage());
41: }
42: }
43: out.write(b, off, len);
44: }
45:
46: public void write(byte[] b) throws IOException {
47: if (myEventHandler != null) {
48: try {
49: myEventHandler.checkCancelled();
50: } catch (final SVNCancelException e) {
51: throw new IOCancelException(e.getMessage());
52: }
53: }
54: out.write(b);
55: }
56:
57: /**
58: * @version 1.1.1
59: * @author TMate Software Ltd.
60: */
61: public static class IOCancelException extends IOException {
62:
63: public IOCancelException(String message) {
64: super(message);
65: }
66: }
67: }
|