01: /* jcifs smb client library in Java
02: * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18:
19: package jcifs.smb;
20:
21: import java.io.OutputStream;
22: import java.io.IOException;
23:
24: class TransactNamedPipeOutputStream extends OutputStream {
25:
26: private String path;
27: private SmbNamedPipe pipe;
28: private byte[] tmp = new byte[1];
29: private boolean dcePipe;
30:
31: TransactNamedPipeOutputStream(SmbNamedPipe pipe) throws IOException {
32: this .pipe = pipe;
33: this .dcePipe = (pipe.pipeType & SmbNamedPipe.PIPE_TYPE_DCE_TRANSACT) == SmbNamedPipe.PIPE_TYPE_DCE_TRANSACT;
34: path = pipe.unc;
35: }
36:
37: public void close() throws IOException {
38: pipe.close();
39: }
40:
41: public void write(int b) throws IOException {
42: tmp[0] = (byte) b;
43: write(tmp, 0, 1);
44: }
45:
46: public void write(byte[] b) throws IOException {
47: write(b, 0, b.length);
48: }
49:
50: public void write(byte[] b, int off, int len) throws IOException {
51: if (len < 0) {
52: len = 0;
53: }
54:
55: if ((pipe.pipeType & SmbNamedPipe.PIPE_TYPE_CALL) == SmbNamedPipe.PIPE_TYPE_CALL) {
56: pipe.sendTransaction(new TransWaitNamedPipe(path),
57: new TransWaitNamedPipeResponse());
58: pipe.sendTransaction(new TransCallNamedPipe(path, b, off,
59: len), new TransCallNamedPipeResponse(pipe));
60: } else if ((pipe.pipeType & SmbNamedPipe.PIPE_TYPE_TRANSACT) == SmbNamedPipe.PIPE_TYPE_TRANSACT) {
61: pipe.open((pipe.pipeType & 0xFFFF0000) | SmbFile.O_EXCL,
62: SmbFile.ATTR_NORMAL, 0);
63: TransTransactNamedPipe req = new TransTransactNamedPipe(
64: pipe.fid, b, off, len);
65: if (dcePipe) {
66: req.maxDataCount = 1024;
67: }
68: pipe.sendTransaction(req,
69: new TransTransactNamedPipeResponse(pipe));
70: }
71: }
72: }
|