1 /* |
1 /* |
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
39 |
37 |
40 public DataSourceStreamingDataHandler(DataSource ds) { |
38 public DataSourceStreamingDataHandler(DataSource ds) { |
41 super(ds); |
39 super(ds); |
42 } |
40 } |
43 |
41 |
|
42 @Override |
44 public InputStream readOnce() throws IOException { |
43 public InputStream readOnce() throws IOException { |
45 return getInputStream(); |
44 return getInputStream(); |
46 } |
45 } |
47 |
46 |
|
47 @Override |
48 public void moveTo(File file) throws IOException { |
48 public void moveTo(File file) throws IOException { |
49 InputStream in = getInputStream(); |
49 InputStream in = getInputStream(); |
50 OutputStream os = new FileOutputStream(file); |
50 OutputStream os = new FileOutputStream(file); |
51 byte[] temp = new byte[8192]; |
51 try { |
52 int len; |
52 byte[] temp = new byte[8192]; |
53 while((len=in.read(temp)) != -1) { |
53 int len; |
54 os.write(temp, 0, len); |
54 while((len=in.read(temp)) != -1) { |
|
55 os.write(temp, 0, len); |
|
56 } |
|
57 in.close(); |
|
58 } finally { |
|
59 if (os != null) { |
|
60 os.close(); |
|
61 } |
55 } |
62 } |
56 in.close(); |
|
57 os.close(); |
|
58 } |
63 } |
59 |
64 |
|
65 @Override |
60 public void close() throws IOException { |
66 public void close() throws IOException { |
61 // nothing to do here |
67 // nothing to do here |
62 } |
68 } |
63 |
69 |
64 } |
70 } |