annotate src/main/java/org/monetdb/jdbc/MonetBlob.java @ 451:3dfcd06fd8ba

Correcting typos in documentation text. Also improved the readability of the generated javadoc documents.
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Thu, 04 Mar 2021 18:57:51 +0100 (2021-03-04)
parents bf9f6b6ecf40
children 6aa38e8c0f2d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
1 /*
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
2 * This Source Code Form is subject to the terms of the Mozilla Public
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
5 *
406
bf9f6b6ecf40 Update Copyright year.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 391
diff changeset
6 * Copyright 1997 - July 2008 CWI, August 2008 - 2021 MonetDB B.V.
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
7 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
8
391
f523727db392 Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 350
diff changeset
9 package org.monetdb.jdbc;
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
10
69
e092fa8d9ab7 Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
11 import java.io.ByteArrayInputStream;
e092fa8d9ab7 Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
12 import java.io.InputStream;
e092fa8d9ab7 Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
13 import java.io.OutputStream;
e092fa8d9ab7 Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
14 import java.sql.Blob;
e092fa8d9ab7 Expand import java.*.* statements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 0
diff changeset
15 import java.sql.SQLException;
266
eefa7f625673 Resolve javadoc errors:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 262
diff changeset
16 import java.sql.SQLFeatureNotSupportedException;
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
17
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
18 /**
451
3dfcd06fd8ba Correcting typos in documentation text. Also improved the readability of the generated javadoc documents.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 406
diff changeset
19 *<pre>
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
20 * The MonetBlob class implements the {@link java.sql.Blob} interface.
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
21 *
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
22 * Because MonetDB/SQL currently has no support for streams, this class is a
451
3dfcd06fd8ba Correcting typos in documentation text. Also improved the readability of the generated javadoc documents.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 406
diff changeset
23 * shallow wrapper of a byte[]. It is more or less supplied to
3dfcd06fd8ba Correcting typos in documentation text. Also improved the readability of the generated javadoc documents.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 406
diff changeset
24 * enable an application that depends on it to run. It may be obvious
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
25 * that it is a real resource expensive workaround that contradicts the
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
26 * benefits for a Blob: avoidance of huge resource consumption.
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
27 * <b>Use of this class is highly discouraged.</b>
451
3dfcd06fd8ba Correcting typos in documentation text. Also improved the readability of the generated javadoc documents.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 406
diff changeset
28 *</pre>
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
29 *
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
30 * @author Fabian Groffen
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
31 */
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
32 public final class MonetBlob implements Blob {
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
33 private byte[] buf;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
34
329
05c7989eae91 Removed duplicate code for converting a string of hex characters into a byte array, done both in MonetBlob.create() and in MonetResultSet.getBytes().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 316
diff changeset
35 /* constructors */
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
36 protected MonetBlob(final byte[] data) {
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
37 buf = data;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
38 }
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
39
329
05c7989eae91 Removed duplicate code for converting a string of hex characters into a byte array, done both in MonetBlob.create() and in MonetResultSet.getBytes().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 316
diff changeset
40 protected MonetBlob(final String hexString) {
05c7989eae91 Removed duplicate code for converting a string of hex characters into a byte array, done both in MonetBlob.create() and in MonetResultSet.getBytes().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 316
diff changeset
41 buf = hexStrToByteArray(hexString);
05c7989eae91 Removed duplicate code for converting a string of hex characters into a byte array, done both in MonetBlob.create() and in MonetResultSet.getBytes().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 316
diff changeset
42 }
05c7989eae91 Removed duplicate code for converting a string of hex characters into a byte array, done both in MonetBlob.create() and in MonetResultSet.getBytes().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 316
diff changeset
43
05c7989eae91 Removed duplicate code for converting a string of hex characters into a byte array, done both in MonetBlob.create() and in MonetResultSet.getBytes().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 316
diff changeset
44
05c7989eae91 Removed duplicate code for converting a string of hex characters into a byte array, done both in MonetBlob.create() and in MonetResultSet.getBytes().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 316
diff changeset
45 /* class utility methods */
05c7989eae91 Removed duplicate code for converting a string of hex characters into a byte array, done both in MonetBlob.create() and in MonetResultSet.getBytes().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 316
diff changeset
46 static final byte[] hexStrToByteArray(final String hexString) {
150
c5309def7d4b Improve MonetBlob implementation.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
47 // unpack the HEX (BLOB) notation to real bytes
316
d479475888e3 Replace StringBuilder methods sb.delete(0, sb.length()) with faster sb.setLength(0).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 295
diff changeset
48 final int len = hexString.length() / 2;
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
49 final byte[] buf = new byte[len];
150
c5309def7d4b Improve MonetBlob implementation.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
50 for (int i = 0; i < len; i++) {
316
d479475888e3 Replace StringBuilder methods sb.delete(0, sb.length()) with faster sb.setLength(0).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 295
diff changeset
51 // was buf[i] = (byte)Integer.parseInt(hexString.substring(2 * i, (2 * i) + 2), 16);
d479475888e3 Replace StringBuilder methods sb.delete(0, sb.length()) with faster sb.setLength(0).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 295
diff changeset
52 buf[i] = (byte) ((Character.digit(hexString.charAt(2 * i), 16) << 4)
d479475888e3 Replace StringBuilder methods sb.delete(0, sb.length()) with faster sb.setLength(0).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 295
diff changeset
53 + Character.digit(hexString.charAt((2 * i) +1), 16));
150
c5309def7d4b Improve MonetBlob implementation.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
54 }
329
05c7989eae91 Removed duplicate code for converting a string of hex characters into a byte array, done both in MonetBlob.create() and in MonetResultSet.getBytes().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 316
diff changeset
55 return buf;
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
56 }
150
c5309def7d4b Improve MonetBlob implementation.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
57
c5309def7d4b Improve MonetBlob implementation.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
58 /* internal utility method */
316
d479475888e3 Replace StringBuilder methods sb.delete(0, sb.length()) with faster sb.setLength(0).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 295
diff changeset
59 private final void checkBufIsNotNull() throws SQLException {
150
c5309def7d4b Improve MonetBlob implementation.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
60 if (buf == null)
c5309def7d4b Improve MonetBlob implementation.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
61 throw new SQLException("This MonetBlob has been freed", "M1M20");
c5309def7d4b Improve MonetBlob implementation.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
62 }
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
63
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
64 //== begin interface Blob
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
65
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
66 /**
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
67 * This method frees the Blob object and releases the resources that
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
68 * it holds. The object is invalid once the free method is called.
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
69 *
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
70 * After free has been called, any attempt to invoke a method other
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
71 * than free will result in a SQLException being thrown. If free is
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
72 * called multiple times, the subsequent calls to free are treated
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
73 * as a no-op.
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
74 *
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
75 * @throws SQLException if an error occurs releasing the Blob's resources
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
76 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
77 @Override
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
78 public void free() throws SQLException {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
79 buf = null;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
80 }
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
81
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
82 /**
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
83 * Retrieves the BLOB value designated by this Blob instance as a stream.
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
84 *
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
85 * @return a stream containing the BLOB data
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
86 * @throws SQLException if there is an error accessing the BLOB value
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
87 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
88 @Override
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
89 public InputStream getBinaryStream() throws SQLException {
150
c5309def7d4b Improve MonetBlob implementation.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
90 checkBufIsNotNull();
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
91 return new ByteArrayInputStream(buf);
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
92 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
93
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
94 /**
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
95 * Returns an InputStream object that contains a partial Blob value,
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
96 * starting with the byte specified by pos, which is length bytes in
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
97 * length.
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
98 *
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
99 * @param pos the offset to the first byte of the partial value to
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
100 * be retrieved. The first byte in the Blob is at position 1
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
101 * @param length the length in bytes of the partial value to be retrieved
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
102 * @return InputStream through which the partial Blob value can be read.
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
103 * @throws SQLException if pos is less than 1 or if pos is
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
104 * greater than the number of bytes in the Blob or if pos +
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
105 * length is greater than the number of bytes in the Blob
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
106 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
107 @Override
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
108 public InputStream getBinaryStream(final long pos, final long length)
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
109 throws SQLException
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
110 {
150
c5309def7d4b Improve MonetBlob implementation.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
111 checkBufIsNotNull();
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
112 if (pos < 1 || pos > buf.length) {
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
113 throw new SQLException("Invalid pos value: " + pos, "M1M05");
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
114 }
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
115 if (length < 0 || pos - 1 + length > buf.length) {
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
116 throw new SQLException("Invalid length value: " + length, "M1M05");
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
117 }
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
118 return new ByteArrayInputStream(buf, (int) pos - 1, (int) length);
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
119 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
120
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
121 /**
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
122 * Retrieves all or part of the BLOB value that this Blob object
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
123 * represents, as an array of bytes. This byte array contains up to
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
124 * length consecutive bytes starting at position pos.
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
125 *
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
126 * @param pos the ordinal position of the first byte in the BLOB
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
127 * value to be extracted; the first byte is at position 1.
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
128 * @param length the number of consecutive bytes to be copied
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
129 * @return a byte array containing up to length consecutive bytes
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
130 * from the BLOB value designated by this Blob object,
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
131 * starting with the byte at position pos.
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
132 * @throws SQLException if there is an error accessing the BLOB value
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
133 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
134 @Override
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
135 public byte[] getBytes(final long pos, final int length) throws SQLException {
150
c5309def7d4b Improve MonetBlob implementation.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
136 checkBufIsNotNull();
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
137 if (pos < 1 || pos > buf.length) {
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
138 throw new SQLException("Invalid pos value: " + pos, "M1M05");
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
139 }
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
140 if (length < 0 || pos - 1 + length > buf.length) {
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
141 throw new SQLException("Invalid length value: " + length, "M1M05");
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
142 }
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
143
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
144 try {
150
c5309def7d4b Improve MonetBlob implementation.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
145 return java.util.Arrays.copyOfRange(buf, (int) pos - 1, (int) pos - 1 + length);
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
146 } catch (IndexOutOfBoundsException e) {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
147 throw new SQLException(e.getMessage(), "M0M10");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
148 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
149 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
150
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
151 /**
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
152 * Returns the number of bytes in the BLOB value designated by this
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
153 * Blob object.
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
154 *
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
155 * @return length of the BLOB in bytes
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
156 * @throws SQLException if there is an error accessing the length
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
157 * of the BLOB value
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
158 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
159 @Override
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
160 public long length() throws SQLException {
150
c5309def7d4b Improve MonetBlob implementation.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
161 checkBufIsNotNull();
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
162 return (long)buf.length;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
163 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
164
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
165 /**
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
166 * Retrieves the byte position in the BLOB value designated by this
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
167 * Blob object at which pattern begins. The search begins at position start.
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
168 *
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
169 * @param pattern the Blob object designating the BLOB value for
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
170 * which to search
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
171 * @param start the position in the BLOB value at which to begin
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
172 * searching; the first position is 1
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
173 * @return the position at which the pattern begins, else -1
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
174 * @throws SQLException if there is an error accessing the BLOB value
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
175 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
176 @Override
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
177 public long position(final Blob pattern, final long start) throws SQLException {
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
178 if (pattern == null) {
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
179 throw new SQLException("Missing pattern object", "M1M05");
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
180 }
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
181 // buf and input argument start will be checked in method position(byte{}, long)
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
182 return position(pattern.getBytes(1L, (int)pattern.length()), start);
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
183 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
184
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
185 /**
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
186 * Retrieves the byte position at which the specified byte array
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
187 * pattern begins within the BLOB value that this Blob object
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
188 * represents. The search for pattern begins at position start.
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
189 *
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
190 * @param pattern the byte array for which to search
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
191 * @param start the position at which to begin searching;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
192 * the first position is 1
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
193 * @return the position at which the pattern appears, else -1
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
194 * @throws SQLException if there is an error accessing the BLOB value
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
195 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
196 @Override
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
197 public long position(final byte[] pattern, final long start) throws SQLException {
150
c5309def7d4b Improve MonetBlob implementation.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
198 checkBufIsNotNull();
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
199 if (pattern == null) {
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
200 throw new SQLException("Missing pattern object", "M1M05");
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
201 }
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
202 if (start < 1 || start > buf.length) {
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
203 throw new SQLException("Invalid start value: " + start, "M1M05");
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
204 }
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
205 try {
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
206 final int patternLength = pattern.length;
316
d479475888e3 Replace StringBuilder methods sb.delete(0, sb.length()) with faster sb.setLength(0).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 295
diff changeset
207 final int maxPos = buf.length - patternLength;
d479475888e3 Replace StringBuilder methods sb.delete(0, sb.length()) with faster sb.setLength(0).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 295
diff changeset
208 for (int i = (int)(start - 1); i < maxPos; i++) {
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
209 int j;
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
210 for (j = 0; j < patternLength; j++) {
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
211 if (buf[i + j] != pattern[j])
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
212 break;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
213 }
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
214 if (j == patternLength)
316
d479475888e3 Replace StringBuilder methods sb.delete(0, sb.length()) with faster sb.setLength(0).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 295
diff changeset
215 // found a match
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
216 return i;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
217 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
218 } catch (IndexOutOfBoundsException e) {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
219 throw new SQLException(e.getMessage(), "M0M10");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
220 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
221 return -1;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
222 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
223
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
224 /**
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
225 * Retrieves a stream that can be used to write to the BLOB value
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
226 * that this Blob object represents. The stream begins at position
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
227 * pos. The bytes written to the stream will overwrite the existing
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
228 * bytes in the Blob object starting at the position pos. If the end
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
229 * of the Blob value is reached while writing to the stream, then
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
230 * the length of the Blob value will be increased to accomodate the
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
231 * extra bytes.
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
232 *
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
233 * @param pos the position in the BLOB value at which to start
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
234 * writing; the first position is 1
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
235 * @return a java.io.OutputStream object to which data can be written
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
236 * @throws SQLException if there is an error accessing the BLOB
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
237 * value or if pos is less than 1
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
238 * @throws SQLFeatureNotSupportedException if the JDBC driver does
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
239 * not support this method
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
240 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
241 @Override
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
242 public OutputStream setBinaryStream(final long pos) throws SQLException {
262
2d62ca1f758b Moved utility method newSQLFeatureNotSupportedException(String name) from MonetPreparedStatement.java and MonetResultSet.java
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 261
diff changeset
243 throw MonetWrapper.newSQLFeatureNotSupportedException("setBinaryStream");
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
244 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
245
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
246 /**
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
247 * Writes the given array of bytes to the BLOB value that this Blob
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
248 * object represents, starting at position pos, and returns the
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
249 * number of bytes written.
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
250 *
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
251 * @param pos the position in the BLOB object at which to start writing
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
252 * @param bytes the array of bytes to be written to the BLOB value
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
253 * that this Blob object represents
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
254 * @return the number of bytes written
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
255 * @throws SQLException if there is an error accessing the
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
256 * BLOB value or if pos is less than 1
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
257 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
258 @Override
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
259 public int setBytes(final long pos, final byte[] bytes) throws SQLException {
316
d479475888e3 Replace StringBuilder methods sb.delete(0, sb.length()) with faster sb.setLength(0).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 295
diff changeset
260 // buf and input arguments will be checked in method setBytes(long, byte{}, int, int)
d479475888e3 Replace StringBuilder methods sb.delete(0, sb.length()) with faster sb.setLength(0).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 295
diff changeset
261 final int len = (bytes != null) ? bytes.length : 0;
d479475888e3 Replace StringBuilder methods sb.delete(0, sb.length()) with faster sb.setLength(0).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 295
diff changeset
262 return setBytes(pos, bytes, 1, len);
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
263 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
264
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
265 /**
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
266 * Writes all or part of the given byte array to the BLOB value that
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
267 * this Blob object represents and returns the number of bytes written.
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
268 * Writing starts at position pos in the BLOB value; len bytes from
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
269 * the given byte array are written.
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
270 *
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
271 * @param pos the position in the BLOB object at which to start writing
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
272 * @param bytes the array of bytes to be written to this BLOB object
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
273 * @param offset the offset into the array bytes at which to start
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
274 * reading the bytes to be set
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
275 * @param len the number of bytes to be written to the BLOB value
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
276 * from the array of bytes bytes
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
277 * @return the number of bytes written
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
278 * @throws SQLException if there is an error accessing the
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
279 * BLOB value or if pos is less than 1
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
280 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
281 @Override
316
d479475888e3 Replace StringBuilder methods sb.delete(0, sb.length()) with faster sb.setLength(0).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 295
diff changeset
282 public int setBytes(final long pos, final byte[] bytes, int offset, final int len)
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
283 throws SQLException
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
284 {
150
c5309def7d4b Improve MonetBlob implementation.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
285 checkBufIsNotNull();
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
286 if (bytes == null) {
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
287 throw new SQLException("Missing bytes[] object", "M1M05");
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
288 }
316
d479475888e3 Replace StringBuilder methods sb.delete(0, sb.length()) with faster sb.setLength(0).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 295
diff changeset
289 if (pos < 1 || pos > buf.length) {
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
290 throw new SQLException("Invalid pos value: " + pos, "M1M05");
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
291 }
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
292 if (len < 0 || pos + len > buf.length) {
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
293 throw new SQLException("Invalid len value: " + len, "M1M05");
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
294 }
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
295 if (offset < 0 || offset > bytes.length) {
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
296 throw new SQLException("Invalid offset value: " + offset, "M1M05");
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
297 }
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
298
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
299 try {
316
d479475888e3 Replace StringBuilder methods sb.delete(0, sb.length()) with faster sb.setLength(0).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 295
diff changeset
300 offset--;
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
301 /* transactions? what are you talking about? */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
302 for (int i = (int)pos; i < len; i++)
316
d479475888e3 Replace StringBuilder methods sb.delete(0, sb.length()) with faster sb.setLength(0).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 295
diff changeset
303 buf[i] = bytes[offset + i];
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
304 } catch (IndexOutOfBoundsException e) {
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
305 throw new SQLException(e.getMessage(), "M0M10");
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
306 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
307 return len;
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
308 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
309
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
310 /**
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
311 * Truncates the BLOB value that this Blob object represents to be
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
312 * len bytes in length.
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
313 *
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
314 * @param len the length, in bytes, to which the BLOB value
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
315 * should be truncated
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
316 * @throws SQLException if there is an error accessing the BLOB value
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
317 */
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
318 @Override
295
003ae6d881db Add "final" keyword to method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 266
diff changeset
319 public void truncate(final long len) throws SQLException {
150
c5309def7d4b Improve MonetBlob implementation.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 90
diff changeset
320 checkBufIsNotNull();
209
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
321 if (len < 0 || len > buf.length) {
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
322 throw new SQLException("Invalid len value: " + len, "M1M05");
94131372ad0b Improved implementation of MonetClob and MonetBlob classes by adding checks on validity of input parameters of methods of those classes.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 200
diff changeset
323 }
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
324 if (buf.length > len) {
316
d479475888e3 Replace StringBuilder methods sb.delete(0, sb.length()) with faster sb.setLength(0).
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 295
diff changeset
325 buf = java.util.Arrays.copyOf(buf, (int)len);
0
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
326 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
327 }
a5a898f6886c Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff changeset
328 }