comparison src/main/java/org/monetdb/jdbc/MonetConnection.java @ 554:9fa67487f38a onclient

Doc comment fixes
author Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
date Thu, 16 Sep 2021 10:30:14 +0200 (2021-09-16)
parents 50b15ee1cb5e
children 87feb93330a6
comparison
equal deleted inserted replaced
553:50b15ee1cb5e 554:9fa67487f38a
3331 * with this error message. The connection will remain usable. 3331 * with this error message. The connection will remain usable.
3332 * 3332 *
3333 * This method can only be sent if no data has been sent to the server 3333 * This method can only be sent if no data has been sent to the server
3334 * yet. After data has been sent, you can still throw an 3334 * yet. After data has been sent, you can still throw an
3335 * {@link IOException} but this will terminate the connection. 3335 * {@link IOException} but this will terminate the connection.
3336 * @param errorMessage 3336 * @param errorMessage error message to send
3337 * @throws IOException
3338 */ 3337 */
3339 public void sendError(String errorMessage) throws IOException { 3338 public void sendError(String errorMessage) throws IOException {
3340 if (error != null) { 3339 if (error != null) {
3341 throw new IOException("another error has already been sent: " + error); 3340 throw new IOException("another error has already been sent: " + error);
3342 } 3341 }
3344 } 3343 }
3345 3344
3346 /** 3345 /**
3347 * After every {@code chunkSize} bytes, the server gets the opportunity to 3346 * After every {@code chunkSize} bytes, the server gets the opportunity to
3348 * terminate the upload. 3347 * terminate the upload.
3349 * @param chunkSize
3350 */ 3348 */
3351 public void setChunkSize(int chunkSize) { 3349 public void setChunkSize(int chunkSize) {
3352 this.customChunkSize = chunkSize; 3350 this.customChunkSize = chunkSize;
3353 } 3351 }
3354 3352
3355 /** 3353 /**
3356 * Get a {@link PrintStream} to write data to. 3354 * Get a {@link PrintStream} to write data to.
3357 * 3355 *
3358 * For text mode uploads, the data MUST be validly UTF-8 encoded. 3356 * For text mode uploads, the data MUST be validly UTF-8 encoded.
3359 * @return
3360 * @throws IOException
3361 */ 3357 */
3362 public PrintStream getStream() throws IOException { 3358 public PrintStream getStream() throws IOException {
3363 if (error != null) { 3359 if (error != null) {
3364 throw new IOException("Cannot send data after an error has been sent"); 3360 throw new IOException("Cannot send data after an error has been sent");
3365 } 3361 }
3374 } 3370 }
3375 return print; 3371 return print;
3376 } 3372 }
3377 3373
3378 /** 3374 /**
3379 * Returns true if data or an error has been sent. 3375 * @return true if data or an error has been sent.
3380 * @return
3381 */ 3376 */
3382 public boolean hasBeenUsed() { 3377 public boolean hasBeenUsed() {
3383 return print != null || error != null; 3378 return print != null || error != null;
3384 } 3379 }
3385 3380
3386 /** 3381 /**
3387 * Get the error that was sent, if any 3382 * @return the error that was sent, if any
3388 * @return
3389 */ 3383 */
3390 public String getError() { 3384 public String getError() {
3391 return error; 3385 return error;
3392 } 3386 }
3393 3387
3394 /** 3388 /**
3395 * Read from the given input stream and write it to the server. 3389 * Read from the given input stream and write it to the server.
3396 * 3390 *
3397 * For text mode uploads, the data MUST be validly UTF-8 encoded. 3391 * For text mode uploads, the data MUST be validly UTF-8 encoded.
3398 * @param inputStream
3399 * @throws IOException
3400 */ 3392 */
3401 public void uploadFrom(InputStream inputStream) throws IOException { 3393 public void uploadFrom(InputStream inputStream) throws IOException {
3402 OutputStream s = getStream(); 3394 OutputStream s = getStream();
3403 byte[] buffer = new byte[64 * 1024]; 3395 byte[] buffer = new byte[64 * 1024];
3404 while (true) { 3396 while (true) {
3413 /** 3405 /**
3414 * Read data from the given buffered reader and send it to the server 3406 * Read data from the given buffered reader and send it to the server
3415 * @param reader reader to read from 3407 * @param reader reader to read from
3416 * @param linesToSkip start uploading at line {@code offset}. Value 0 and 1 3408 * @param linesToSkip start uploading at line {@code offset}. Value 0 and 1
3417 * both mean upload the whole file, value 2 means skip the first line, etc.q 3409 * both mean upload the whole file, value 2 means skip the first line, etc.q
3418 * @throws IOException
3419 */ 3410 */
3420 public void uploadFrom(BufferedReader reader, long linesToSkip) throws IOException { 3411 public void uploadFrom(BufferedReader reader, long linesToSkip) throws IOException {
3421 for (int i = 0; i < linesToSkip; i++) { 3412 for (int i = 0; i < linesToSkip; i++) {
3422 String line = reader.readLine(); 3413 String line = reader.readLine();
3423 if (line == null) { 3414 if (line == null) {
3430 3421
3431 3422
3432 /** 3423 /**
3433 * Read data from the given buffered reader and send it to the server 3424 * Read data from the given buffered reader and send it to the server
3434 * @param reader reader to read from 3425 * @param reader reader to read from
3435 * @throws IOException
3436 */ 3426 */
3437 public void uploadFrom(Reader reader) throws IOException { 3427 public void uploadFrom(Reader reader) throws IOException {
3438 OutputStream s = getStream(); 3428 OutputStream s = getStream();
3439 OutputStreamWriter writer = new OutputStreamWriter(s, StandardCharsets.UTF_8); 3429 OutputStreamWriter writer = new OutputStreamWriter(s, StandardCharsets.UTF_8);
3440 char[] buffer = new char[64 * 1024]; 3430 char[] buffer = new char[64 * 1024];
3479 * yet. After data has been received, you can still throw an 3469 * yet. After data has been received, you can still throw an
3480 * {@link IOException} but this will terminate the connection. 3470 * {@link IOException} but this will terminate the connection.
3481 * 3471 *
3482 * Note: as of MonetDB version Jul2021 the server always terminates the connection 3472 * Note: as of MonetDB version Jul2021 the server always terminates the connection
3483 * when this error is used. This will probably change in the future. 3473 * when this error is used. This will probably change in the future.
3484 * @param errorMessage
3485 * @throws IOException
3486 */ 3474 */
3487 public void sendError(String errorMessage) throws IOException { 3475 public void sendError(String errorMessage) throws IOException {
3488 if (error != null) { 3476 if (error != null) {
3489 throw new IOException("another error has already been sent: " + error); 3477 throw new IOException("another error has already been sent: " + error);
3490 } 3478 }
3493 3481
3494 /** 3482 /**
3495 * Get an {@link InputStream} to read data from. 3483 * Get an {@link InputStream} to read data from.
3496 * 3484 *
3497 * Textual data is UTF-8 encoded. 3485 * Textual data is UTF-8 encoded.
3498 * @return
3499 * @throws IOException
3500 */ 3486 */
3501 public InputStream getStream() throws IOException { 3487 public InputStream getStream() throws IOException {
3502 if (error != null) { 3488 if (error != null) {
3503 throw new IOException("cannot receive data after error has been sent"); 3489 throw new IOException("cannot receive data after error has been sent");
3504 } 3490 }
3509 return stream; 3495 return stream;
3510 } 3496 }
3511 3497
3512 /** 3498 /**
3513 * Write the data from the server to the given {@link OutputStream}. 3499 * Write the data from the server to the given {@link OutputStream}.
3514 * @param stream
3515 * @throws IOException
3516 */ 3500 */
3517 public void downloadTo(OutputStream stream) throws IOException { 3501 public void downloadTo(OutputStream stream) throws IOException {
3518 InputStream s = getStream(); 3502 InputStream s = getStream();
3519 byte[] buffer = new byte[65536]; 3503 byte[] buffer = new byte[65536];
3520 while (true) { 3504 while (true) {
3524 stream.write(buffer, 0, nread); 3508 stream.write(buffer, 0, nread);
3525 } 3509 }
3526 } 3510 }
3527 3511
3528 /** 3512 /**
3529 * Returns true if data has been received or an error has been sent. 3513 * @return true if data has been received or an error has been sent.
3530 * @return
3531 */ 3514 */
3532 3515
3533 public boolean hasBeenUsed() { 3516 public boolean hasBeenUsed() {
3534 return error != null || stream != null; 3517 return error != null || stream != null;
3535 } 3518 }
3536 3519
3537 /** 3520 /**
3538 * Get the error that was sent, if any 3521 * @return the error that was sent, if any
3539 * @return
3540 */ 3522 */
3541 3523
3542 public String getError() { 3524 public String getError() {
3543 return error; 3525 return error;
3544 } 3526 }