1 /*
2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
35 import java.net.URL;
36
37 /**
38 * {@link DataHandler} extended to offer better buffer management
39 * in a streaming environment.
40 *
41 * <p>
42 * {@link DataHandler} is used commonly as a data format across
43 * multiple systems (such as JAXB/WS.) Unfortunately, {@link DataHandler}
44 * has the semantics of "read as many times as you want", so this makes
45 * it difficult for involving parties to handle a BLOB in a streaming fashion.
46 *
47 * <p>
48 * {@link StreamingDataHandler} solves this problem by offering methods
49 * that enable faster bulk "consume once" read operation.
50 *
51 * @author Jitendra Kotamraju
52 */
53 public abstract class StreamingDataHandler extends DataHandler implements Closeable {
54
55 public StreamingDataHandler(Object o, String s) {
56 super(o, s);
57 }
58
59 public StreamingDataHandler(URL url) {
60 super(url);
61 }
62
63 public StreamingDataHandler(DataSource dataSource) {
64 super(dataSource);
65 }
66
67 /**
68 * Works like {@link #getInputStream()} except that this method
69 * can be invoked only once.
70 *
71 * <p>
72 * This is used as a signal from the caller that there will
73 * be no further {@link #getInputStream()} invocation nor
74 * {@link #readOnce()} invocation on this object (which would
125 *
126 * <p>
127 * After this method is invoked, {@link #readOnce()} and
128 * {@link #getInputStream()} will simply open the destination
129 * file you've specified as an argument. So if you further
130 * move the file or delete this file, those methods will
131 * behave in undefined fashion. For a simliar reason,
132 * calling this method multiple times will cause
133 * undefined behavior.
134 */
135 public abstract void moveTo(File dst) throws IOException;
136
137 /**
138 * Releases any resources associated with this DataHandler.
139 * (such as an attachment in a web service read from a temp
140 * file will be deleted.) After calling this method, it is
141 * illegal to call any other methods.
142 */
143 public abstract void close() throws IOException;
144
145 }
|
1 /*
2 * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
35 import java.net.URL;
36
37 /**
38 * {@link DataHandler} extended to offer better buffer management
39 * in a streaming environment.
40 *
41 * <p>
42 * {@link DataHandler} is used commonly as a data format across
43 * multiple systems (such as JAXB/WS.) Unfortunately, {@link DataHandler}
44 * has the semantics of "read as many times as you want", so this makes
45 * it difficult for involving parties to handle a BLOB in a streaming fashion.
46 *
47 * <p>
48 * {@link StreamingDataHandler} solves this problem by offering methods
49 * that enable faster bulk "consume once" read operation.
50 *
51 * @author Jitendra Kotamraju
52 */
53 public abstract class StreamingDataHandler extends DataHandler implements Closeable {
54
55 private String hrefCid;
56
57 public StreamingDataHandler(Object o, String s) {
58 super(o, s);
59 }
60
61 public StreamingDataHandler(URL url) {
62 super(url);
63 }
64
65 public StreamingDataHandler(DataSource dataSource) {
66 super(dataSource);
67 }
68
69 /**
70 * Works like {@link #getInputStream()} except that this method
71 * can be invoked only once.
72 *
73 * <p>
74 * This is used as a signal from the caller that there will
75 * be no further {@link #getInputStream()} invocation nor
76 * {@link #readOnce()} invocation on this object (which would
127 *
128 * <p>
129 * After this method is invoked, {@link #readOnce()} and
130 * {@link #getInputStream()} will simply open the destination
131 * file you've specified as an argument. So if you further
132 * move the file or delete this file, those methods will
133 * behave in undefined fashion. For a simliar reason,
134 * calling this method multiple times will cause
135 * undefined behavior.
136 */
137 public abstract void moveTo(File dst) throws IOException;
138
139 /**
140 * Releases any resources associated with this DataHandler.
141 * (such as an attachment in a web service read from a temp
142 * file will be deleted.) After calling this method, it is
143 * illegal to call any other methods.
144 */
145 public abstract void close() throws IOException;
146
147 public String getHrefCid() {
148 return hrefCid;
149 }
150
151 public void setHrefCid(final String cid) {
152 this.hrefCid = cid;
153 }
154 }
|