| 1 |
/* |
| 2 |
* Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0, |
| 3 |
* and the EPL 1.0 (https://h2database.com/html/license.html). |
| 4 |
* Initial Developer: H2 Group |
| 5 |
*/ |
| 6 |
package org.h2.util; |
| 7 |
|
| 8 |
import java.io.ByteArrayOutputStream; |
| 9 |
import java.io.IOException; |
| 10 |
import java.io.UnsupportedEncodingException; |
| 11 |
import java.net.Socket; |
| 12 |
import java.nio.charset.Charset; |
| 13 |
|
| 14 |
/** |
| 15 |
* Utilities with specialized implementations for Java 10 and later versions. |
| 16 |
* |
| 17 |
* This class contains basic implementations for Java 8 and 9 and it is |
| 18 |
* overridden in multi-release JARs. |
| 19 |
*/ |
| 20 |
public final class Utils10 { |
| 21 |
|
| 22 |
/* |
| 23 |
* Signatures of methods should match with |
| 24 |
* h2/src/java10/src/org/h2/util/Utils10.java and precompiled |
| 25 |
* h2/src/java10/precompiled/org/h2/util/Utils10.class. |
| 26 |
*/ |
| 27 |
|
| 28 |
/** |
| 29 |
* Converts the buffer's contents into a string by decoding the bytes using |
| 30 |
* the specified {@link java.nio.charset.Charset charset}. |
| 31 |
* |
| 32 |
* @param baos |
| 33 |
* the buffer to decode |
| 34 |
* @param charset |
| 35 |
* the charset to use |
| 36 |
* @return the decoded string |
| 37 |
*/ |
| 38 |
public static String byteArrayOutputStreamToString(ByteArrayOutputStream baos, Charset charset) { |
| 39 |
try { |
| 40 |
return baos.toString(charset.name()); |
| 41 |
} catch (UnsupportedEncodingException e) { |
| 42 |
throw new RuntimeException(e); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Returns the value of TCP_QUICKACK option. |
| 48 |
* |
| 49 |
* @param socket |
| 50 |
* the socket |
| 51 |
* @return the current value of TCP_QUICKACK option |
| 52 |
* @throws IOException |
| 53 |
* on I/O exception |
| 54 |
* @throws UnsupportedOperationException |
| 55 |
* if TCP_QUICKACK is not supported |
| 56 |
*/ |
| 57 |
public static boolean getTcpQuickack(Socket socket) throws IOException { |
| 58 |
throw new UnsupportedOperationException(); |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Sets the value of TCP_QUICKACK option. |
| 63 |
* |
| 64 |
* @param socket |
| 65 |
* the socket |
| 66 |
* @param value |
| 67 |
* the value to set |
| 68 |
* @return whether operation was successful |
| 69 |
*/ |
| 70 |
public static boolean setTcpQuickack(Socket socket, boolean value) { |
| 71 |
// The default implementation does nothing |
| 72 |
return false; |
| 73 |
} |
| 74 |
|
| 75 |
private Utils10() { |
| 76 |
} |
| 77 |
|
| 78 |
} |