code
stringlengths
25
201k
docstring
stringlengths
19
96.2k
func_name
stringlengths
0
235
language
stringclasses
1 value
repo
stringlengths
8
51
path
stringlengths
11
314
url
stringlengths
62
377
license
stringclasses
7 values
public void substring(StringValue target, int start) { substring(target, start, this.len); }
Copies a substring of this string into the given target StringValue. The substring begins at the given <code>start</code> index and ends at end of the string @param target The StringValue object to copy the substring to. @param start The beginning index, inclusive. @exception IndexOutOfBoundsException Thrown, if the start is negative.
substring
java
apache/flink
flink-core/src/main/java/org/apache/flink/types/StringValue.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/types/StringValue.java
Apache-2.0
public void substring(StringValue target, int start, int end) { target.setValue(this, start, end - start); }
Copies a substring of this string into the given target StringValue. The substring begins at the given <code>start</code> index and ends at <code>end - 1</code>. @param target The StringValue object to copy the substring to. @param start The beginning index, inclusive. @param end The ending index, exclusive. @exception IndexOutOfBoundsException Thrown, if the start is negative, or the end is larger than the length.
substring
java
apache/flink
flink-core/src/main/java/org/apache/flink/types/StringValue.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/types/StringValue.java
Apache-2.0
public int find(CharSequence str) { return find(str, 0); }
Finds any occurrence of the <code>str</code> character sequence in this StringValue. @return The position of the first occurrence of the search string in the string value, or <code>-1</code>, if the character sequence was not found.
find
java
apache/flink
flink-core/src/main/java/org/apache/flink/types/StringValue.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/types/StringValue.java
Apache-2.0
public int find(CharSequence str, int start) { final int pLen = this.len; final int sLen = str.length(); if (sLen == 0) { throw new IllegalArgumentException("Cannot find empty string."); } int pPos = start; final char first = str.charAt(0); while (pPos < pLen) { if (first == this.value[pPos++]) { // matching first character final int fallBackPosition = pPos; int sPos = 1; boolean found = true; while (sPos < sLen) { if (pPos >= pLen) { // no more characters in string value pPos = fallBackPosition; found = false; break; } if (str.charAt(sPos++) != this.value[pPos++]) { pPos = fallBackPosition; found = false; break; } } if (found) { return fallBackPosition - 1; } } } return -1; }
Finds any occurrence of the <code>str</code> character sequence in this StringValue. The search starts at position <code>start</code>. @return The position of the first occurrence of the search string in the string value, or <code>-1</code>, if the character sequence was not found.
find
java
apache/flink
flink-core/src/main/java/org/apache/flink/types/StringValue.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/types/StringValue.java
Apache-2.0
public boolean startsWith(CharSequence prefix, int startIndex) { final char[] thisChars = this.value; final int pLen = this.len; final int sLen = prefix.length(); if ((startIndex < 0) || (startIndex > pLen - sLen)) { return false; } int sPos = 0; while (sPos < sLen) { if (thisChars[startIndex++] != prefix.charAt(sPos++)) { return false; } } return true; }
Checks whether the substring, starting at the specified index, starts with the given prefix string. @param prefix The prefix character sequence. @param startIndex The position to start checking for the prefix. @return True, if this StringValue substring, starting at position <code>startIndex</code> has <code>prefix</code> as its prefix.
startsWith
java
apache/flink
flink-core/src/main/java/org/apache/flink/types/StringValue.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/types/StringValue.java
Apache-2.0
public static final BigDecimal parseField(byte[] bytes, int startPos, int length) { return parseField(bytes, startPos, length, (char) 0xffff); }
Static utility to parse a field of type BigDecimal from a byte sequence that represents text characters (such as when read from a file stream). @param bytes The bytes containing the text data that should be parsed. @param startPos The offset to start the parsing. @param length The length of the byte sequence (counting from the offset). @return The parsed value. @throws IllegalArgumentException Thrown when the value cannot be parsed because the text represents not a correct number.
parseField
java
apache/flink
flink-core/src/main/java/org/apache/flink/types/parser/BigDecParser.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/types/parser/BigDecParser.java
Apache-2.0
public static final BigInteger parseField(byte[] bytes, int startPos, int length) { return parseField(bytes, startPos, length, (char) 0xffff); }
Static utility to parse a field of type BigInteger from a byte sequence that represents text characters (such as when read from a file stream). @param bytes The bytes containing the text data that should be parsed. @param startPos The offset to start the parsing. @param length The length of the byte sequence (counting from the offset). @return The parsed value. @throws IllegalArgumentException Thrown when the value cannot be parsed because the text represents not a correct number.
parseField
java
apache/flink
flink-core/src/main/java/org/apache/flink/types/parser/BigIntParser.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/types/parser/BigIntParser.java
Apache-2.0
private static boolean byteArrayEquals(byte[] source, int start, int length, byte[] other) { if (length != other.length) { return false; } for (int i = 0; i < other.length; i++) { if (Character.toLowerCase(source[i + start]) != other[i]) { return false; } } return true; }
Checks if a part of a byte array matches another byte array with chars (case-insensitive). @param source The source byte array. @param start The offset into the source byte array. @param length The length of the match. @param other The byte array which is fully compared to the part of the source array. @return true if other can be found in the specified part of source, false otherwise.
byteArrayEquals
java
apache/flink
flink-core/src/main/java/org/apache/flink/types/parser/BooleanParser.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/types/parser/BooleanParser.java
Apache-2.0
public static final byte parseField(byte[] bytes, int startPos, int length) { return parseField(bytes, startPos, length, (char) 0xffff); }
Static utility to parse a field of type byte from a byte sequence that represents text characters (such as when read from a file stream). @param bytes The bytes containing the text data that should be parsed. @param startPos The offset to start the parsing. @param length The length of the byte sequence (counting from the offset). @return The parsed value. @throws NumberFormatException Thrown when the value cannot be parsed because the text represents not a correct number.
parseField
java
apache/flink
flink-core/src/main/java/org/apache/flink/types/parser/ByteParser.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/types/parser/ByteParser.java
Apache-2.0
public static final double parseField(byte[] bytes, int startPos, int length) { return parseField(bytes, startPos, length, (char) 0xffff); }
Static utility to parse a field of type double from a byte sequence that represents text characters (such as when read from a file stream). @param bytes The bytes containing the text data that should be parsed. @param startPos The offset to start the parsing. @param length The length of the byte sequence (counting from the offset). @return The parsed value. @throws IllegalArgumentException Thrown when the value cannot be parsed because the text represents not a correct number.
parseField
java
apache/flink
flink-core/src/main/java/org/apache/flink/types/parser/DoubleParser.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/types/parser/DoubleParser.java
Apache-2.0
protected void resetParserState() { this.errorState = ParseErrorState.NONE; }
Reset the state of the parser. Called as the very first method inside {@link FieldParser#resetErrorStateAndParse(byte[], int, int, byte[], Object)}, by default it just reset its error state.
resetParserState
java
apache/flink
flink-core/src/main/java/org/apache/flink/types/parser/FieldParser.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/types/parser/FieldParser.java
Apache-2.0
protected void setErrorState(ParseErrorState error) { this.errorState = error; }
Sets the error state of the parser. Called by subclasses of the parser to set the type of error when failing a parse. @param error The error state to set.
setErrorState
java
apache/flink
flink-core/src/main/java/org/apache/flink/types/parser/FieldParser.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/types/parser/FieldParser.java
Apache-2.0
public ParseErrorState getErrorState() { return this.errorState; }
Gets the error state of the parser, as a value of the enumeration {@link ParseErrorState}. If no error occurred, the error state will be {@link ParseErrorState#NONE}. @return The current error state of the parser.
getErrorState
java
apache/flink
flink-core/src/main/java/org/apache/flink/types/parser/FieldParser.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/types/parser/FieldParser.java
Apache-2.0
protected final int nextStringEndPos(byte[] bytes, int startPos, int limit, byte[] delimiter) { int endPos = startPos; final int delimLimit = limit - delimiter.length + 1; while (endPos < limit) { if (endPos < delimLimit && delimiterNext(bytes, endPos, delimiter)) { break; } endPos++; } if (endPos == startPos) { setErrorState(ParseErrorState.EMPTY_COLUMN); return -1; } return endPos; }
Returns the end position of a string. Sets the error state if the column is empty. @return the end position of the string or -1 if an error occurred
nextStringEndPos
java
apache/flink
flink-core/src/main/java/org/apache/flink/types/parser/FieldParser.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/types/parser/FieldParser.java
Apache-2.0
protected static final int nextStringLength( byte[] bytes, int startPos, int length, char delimiter) { if (length <= 0) { throw new IllegalArgumentException("Invalid input: Empty string"); } int limitedLength = 0; final byte delByte = (byte) delimiter; while (limitedLength < length && bytes[startPos + limitedLength] != delByte) { limitedLength++; } return limitedLength; }
Returns the length of a string. Throws an exception if the column is empty. @return the length of the string
nextStringLength
java
apache/flink
flink-core/src/main/java/org/apache/flink/types/parser/FieldParser.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/types/parser/FieldParser.java
Apache-2.0
public Charset getCharset() { return this.charset; }
Gets the character set used for this parser. @return the charset used for this parser.
getCharset
java
apache/flink
flink-core/src/main/java/org/apache/flink/types/parser/FieldParser.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/types/parser/FieldParser.java
Apache-2.0
public void setCharset(Charset charset) { this.charset = charset; }
Sets the character set used for this parser. @param charset charset used for this parser.
setCharset
java
apache/flink
flink-core/src/main/java/org/apache/flink/types/parser/FieldParser.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/types/parser/FieldParser.java
Apache-2.0
public static <T> Class<FieldParser<T>> getParserForType(Class<T> type) { Class<? extends FieldParser<?>> parser = PARSERS.get(type); if (parser == null) { return null; } else { @SuppressWarnings("unchecked") Class<FieldParser<T>> typedParser = (Class<FieldParser<T>>) parser; return typedParser; } }
Gets the parser for the type specified by the given class. Returns null, if no parser for that class is known. @param type The class of the type to get the parser for. @return The parser for the given type, or null, if no such parser exists.
getParserForType
java
apache/flink
flink-core/src/main/java/org/apache/flink/types/parser/FieldParser.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/types/parser/FieldParser.java
Apache-2.0
public static final float parseField(byte[] bytes, int startPos, int length) { return parseField(bytes, startPos, length, (char) 0xffff); }
Static utility to parse a field of type float from a byte sequence that represents text characters (such as when read from a file stream). @param bytes The bytes containing the text data that should be parsed. @param startPos The offset to start the parsing. @param length The length of the byte sequence (counting from the offset). @return The parsed value. @throws IllegalArgumentException Thrown when the value cannot be parsed because the text represents not a correct number.
parseField
java
apache/flink
flink-core/src/main/java/org/apache/flink/types/parser/FloatParser.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/types/parser/FloatParser.java
Apache-2.0
public static final int parseField(byte[] bytes, int startPos, int length) { return parseField(bytes, startPos, length, (char) 0xffff); }
Static utility to parse a field of type int from a byte sequence that represents text characters (such as when read from a file stream). @param bytes The bytes containing the text data that should be parsed. @param startPos The offset to start the parsing. @param length The length of the byte sequence (counting from the offset). @return The parsed value. @throws NumberFormatException Thrown when the value cannot be parsed because the text represents not a correct number.
parseField
java
apache/flink
flink-core/src/main/java/org/apache/flink/types/parser/IntParser.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/types/parser/IntParser.java
Apache-2.0
public static final long parseField(byte[] bytes, int startPos, int length) { return parseField(bytes, startPos, length, (char) 0xffff); }
Static utility to parse a field of type long from a byte sequence that represents text characters (such as when read from a file stream). @param bytes The bytes containing the text data that should be parsed. @param startPos The offset to start the parsing. @param length The length of the byte sequence (counting from the offset). @return The parsed value. @throws NumberFormatException Thrown when the value cannot be parsed because the text represents not a correct number.
parseField
java
apache/flink
flink-core/src/main/java/org/apache/flink/types/parser/LongParser.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/types/parser/LongParser.java
Apache-2.0
public static final short parseField(byte[] bytes, int startPos, int length) { return parseField(bytes, startPos, length, (char) 0xffff); }
Static utility to parse a field of type short from a byte sequence that represents text characters (such as when read from a file stream). @param bytes The bytes containing the text data that should be parsed. @param startPos The offset to start the parsing. @param length The length of the byte sequence (counting from the offset). @return The parsed value. @throws NumberFormatException Thrown when the value cannot be parsed because the text represents not a correct number.
parseField
java
apache/flink
flink-core/src/main/java/org/apache/flink/types/parser/ShortParser.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/types/parser/ShortParser.java
Apache-2.0
public static final Date parseField(byte[] bytes, int startPos, int length) { return parseField(bytes, startPos, length, (char) 0xffff); }
Static utility to parse a field of type Date from a byte sequence that represents text characters (such as when read from a file stream). @param bytes The bytes containing the text data that should be parsed. @param startPos The offset to start the parsing. @param length The length of the byte sequence (counting from the offset). @return The parsed value. @throws IllegalArgumentException Thrown when the value cannot be parsed because the text represents not a correct number.
parseField
java
apache/flink
flink-core/src/main/java/org/apache/flink/types/parser/SqlDateParser.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/types/parser/SqlDateParser.java
Apache-2.0
public static final Time parseField(byte[] bytes, int startPos, int length) { return parseField(bytes, startPos, length, (char) 0xffff); }
Static utility to parse a field of type Time from a byte sequence that represents text characters (such as when read from a file stream). @param bytes The bytes containing the text data that should be parsed. @param startPos The offset to start the parsing. @param length The length of the byte sequence (counting from the offset). @return The parsed value. @throws IllegalArgumentException Thrown when the value cannot be parsed because the text represents not a correct number.
parseField
java
apache/flink
flink-core/src/main/java/org/apache/flink/types/parser/SqlTimeParser.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/types/parser/SqlTimeParser.java
Apache-2.0
public static final Timestamp parseField(byte[] bytes, int startPos, int length) { return parseField(bytes, startPos, length, (char) 0xffff); }
Static utility to parse a field of type Timestamp from a byte sequence that represents text characters (such as when read from a file stream). @param bytes The bytes containing the text data that should be parsed. @param startPos The offset to start the parsing. @param length The length of the byte sequence (counting from the offset). @return The parsed value. @throws IllegalArgumentException Thrown when the value cannot be parsed because the text represents not a correct number.
parseField
java
apache/flink
flink-core/src/main/java/org/apache/flink/types/parser/SqlTimestampParser.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/types/parser/SqlTimestampParser.java
Apache-2.0
public final void registerCloseable(C closeable) throws IOException { if (null == closeable) { return; } synchronized (getSynchronizationLock()) { if (!closed) { doRegister(closeable, closeableToRef); return; } } IOUtils.closeQuietly(closeable); throw new IOException( "Cannot register Closeable, registry is already closed. Closing argument."); }
Registers a {@link AutoCloseable} with the registry. In case the registry is already closed, this method throws an {@link IllegalStateException} and closes the passed {@link AutoCloseable}. @param closeable Closeable to register. @throws IOException exception when the registry was closed before.
registerCloseable
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/AbstractAutoCloseableRegistry.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/AbstractAutoCloseableRegistry.java
Apache-2.0
protected final Object getSynchronizationLock() { return lock; }
Returns the lock on which manipulations to members closeableToRef and closeable must be synchronized.
getSynchronizationLock
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/AbstractAutoCloseableRegistry.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/AbstractAutoCloseableRegistry.java
Apache-2.0
public long getLowerPart() { return lowerPart; }
Gets the lower 64 bits of the ID. @return The lower 64 bits of the ID.
getLowerPart
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/AbstractID.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/AbstractID.java
Apache-2.0
public long getUpperPart() { return upperPart; }
Gets the upper 64 bits of the ID. @return The upper 64 bits of the ID.
getUpperPart
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/AbstractID.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/AbstractID.java
Apache-2.0
public byte[] getBytes() { byte[] bytes = new byte[SIZE]; longToByteArray(lowerPart, bytes, 0); longToByteArray(upperPart, bytes, SIZE_OF_LONG); return bytes; }
Gets the bytes underlying this ID. @return The bytes underlying this ID.
getBytes
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/AbstractID.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/AbstractID.java
Apache-2.0
private static long byteArrayToLong(byte[] ba, int offset) { long l = 0; for (int i = 0; i < SIZE_OF_LONG; ++i) { l |= (ba[offset + SIZE_OF_LONG - 1 - i] & 0xffL) << (i << 3); } return l; }
Converts the given byte array to a long. @param ba the byte array to be converted @param offset the offset indicating at which byte inside the array the conversion shall begin @return the long variable
byteArrayToLong
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/AbstractID.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/AbstractID.java
Apache-2.0
private static void longToByteArray(long l, byte[] ba, int offset) { for (int i = 0; i < SIZE_OF_LONG; ++i) { final int shift = i << 3; // i * 8 ba[offset + SIZE_OF_LONG - 1 - i] = (byte) ((l & (0xffL << shift)) >>> shift); } }
Converts a long to a byte array. @param l the long variable to be converted @param ba the byte array to store the result the of the conversion @param offset offset indicating at what position inside the byte array the result of the conversion shall be stored
longToByteArray
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/AbstractID.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/AbstractID.java
Apache-2.0
@PublicEvolving public Set<String> getUnrequestedParameters() { return Collections.unmodifiableSet(unrequestedParameters); }
Returns the set of parameter names which have not been requested with {@link #has(String)} or one of the {@code get} methods. Access to the map returned by {@link #toMap()} is not tracked.
getUnrequestedParameters
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/AbstractParameterTool.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/AbstractParameterTool.java
Apache-2.0
public String getRequired(String key) { addToDefaults(key, null); String value = get(key); if (value == null) { throw new RuntimeException("No data for required key '" + key + "'"); } return value; }
Returns the String value for the given key. If the key does not exist it will throw a {@link RuntimeException}.
getRequired
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/AbstractParameterTool.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/AbstractParameterTool.java
Apache-2.0
public String get(String key, String defaultValue) { addToDefaults(key, defaultValue); String value = get(key); if (value == null) { return defaultValue; } else { return value; } }
Returns the String value for the given key. If the key does not exist it will return the given default value.
get
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/AbstractParameterTool.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/AbstractParameterTool.java
Apache-2.0
public int getInt(String key) { addToDefaults(key, null); String value = getRequired(key); return Integer.parseInt(value); }
Returns the Integer value for the given key. The method fails if the key does not exist or the value is not an Integer.
getInt
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/AbstractParameterTool.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/AbstractParameterTool.java
Apache-2.0
public int getInt(String key, int defaultValue) { addToDefaults(key, Integer.toString(defaultValue)); String value = get(key); if (value == null) { return defaultValue; } return Integer.parseInt(value); }
Returns the Integer value for the given key. If the key does not exists it will return the default value given. The method fails if the value is not an Integer.
getInt
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/AbstractParameterTool.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/AbstractParameterTool.java
Apache-2.0
public long getLong(String key) { addToDefaults(key, null); String value = getRequired(key); return Long.parseLong(value); }
Returns the Long value for the given key. The method fails if the key does not exist.
getLong
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/AbstractParameterTool.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/AbstractParameterTool.java
Apache-2.0
public long getLong(String key, long defaultValue) { addToDefaults(key, Long.toString(defaultValue)); String value = get(key); if (value == null) { return defaultValue; } return Long.parseLong(value); }
Returns the Long value for the given key. If the key does not exists it will return the default value given. The method fails if the value is not a Long.
getLong
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/AbstractParameterTool.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/AbstractParameterTool.java
Apache-2.0
public float getFloat(String key) { addToDefaults(key, null); String value = getRequired(key); return Float.valueOf(value); }
Returns the Float value for the given key. The method fails if the key does not exist.
getFloat
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/AbstractParameterTool.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/AbstractParameterTool.java
Apache-2.0
public float getFloat(String key, float defaultValue) { addToDefaults(key, Float.toString(defaultValue)); String value = get(key); if (value == null) { return defaultValue; } else { return Float.valueOf(value); } }
Returns the Float value for the given key. If the key does not exists it will return the default value given. The method fails if the value is not a Float.
getFloat
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/AbstractParameterTool.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/AbstractParameterTool.java
Apache-2.0
public double getDouble(String key) { addToDefaults(key, null); String value = getRequired(key); return Double.valueOf(value); }
Returns the Double value for the given key. The method fails if the key does not exist.
getDouble
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/AbstractParameterTool.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/AbstractParameterTool.java
Apache-2.0
public double getDouble(String key, double defaultValue) { addToDefaults(key, Double.toString(defaultValue)); String value = get(key); if (value == null) { return defaultValue; } else { return Double.valueOf(value); } }
Returns the Double value for the given key. If the key does not exists it will return the default value given. The method fails if the value is not a Double.
getDouble
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/AbstractParameterTool.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/AbstractParameterTool.java
Apache-2.0
public boolean getBoolean(String key) { addToDefaults(key, null); String value = getRequired(key); return Boolean.valueOf(value); }
Returns the Boolean value for the given key. The method fails if the key does not exist.
getBoolean
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/AbstractParameterTool.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/AbstractParameterTool.java
Apache-2.0
public boolean getBoolean(String key, boolean defaultValue) { addToDefaults(key, Boolean.toString(defaultValue)); String value = get(key); if (value == null) { return defaultValue; } else { return Boolean.valueOf(value); } }
Returns the Boolean value for the given key. If the key does not exists it will return the default value given. The method returns whether the string of the value is "true" ignoring cases.
getBoolean
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/AbstractParameterTool.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/AbstractParameterTool.java
Apache-2.0
public short getShort(String key) { addToDefaults(key, null); String value = getRequired(key); return Short.valueOf(value); }
Returns the Short value for the given key. The method fails if the key does not exist.
getShort
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/AbstractParameterTool.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/AbstractParameterTool.java
Apache-2.0
public short getShort(String key, short defaultValue) { addToDefaults(key, Short.toString(defaultValue)); String value = get(key); if (value == null) { return defaultValue; } else { return Short.valueOf(value); } }
Returns the Short value for the given key. If the key does not exists it will return the default value given. The method fails if the value is not a Short.
getShort
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/AbstractParameterTool.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/AbstractParameterTool.java
Apache-2.0
public byte getByte(String key) { addToDefaults(key, null); String value = getRequired(key); return Byte.valueOf(value); }
Returns the Byte value for the given key. The method fails if the key does not exist.
getByte
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/AbstractParameterTool.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/AbstractParameterTool.java
Apache-2.0
default void close() throws Exception { try { closeAsync().get(); } catch (ExecutionException e) { throw new FlinkException( "Could not close resource.", ExceptionUtils.stripExecutionException(e)); } }
Trigger the closing of the resource and return the corresponding close future. @return Future which is completed once the resource has been closed
close
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/AutoCloseableAsync.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/AutoCloseableAsync.java
Apache-2.0
public static String getUserCodeClassLoaderInfo(ClassLoader loader) { if (loader instanceof URLClassLoader) { URLClassLoader cl = (URLClassLoader) loader; try { StringBuilder bld = new StringBuilder(); if (cl == ClassLoader.getSystemClassLoader()) { bld.append("System ClassLoader: "); } else { bld.append("URL ClassLoader:"); } for (URL url : cl.getURLs()) { bld.append(formatURL(url)); } return bld.toString(); } catch (Throwable t) { return "Cannot access classloader info due to an exception.\n" + ExceptionUtils.stringifyException(t); } } else if (loader == ClassLoader.getSystemClassLoader()) { // this branch is only reachable on Java9+ // where the system classloader is no longer a URLClassLoader return "System ClassLoader"; } else { return "No user code ClassLoader"; } }
Gets information about URL class loaders. The returned info string contains all URLs of the class loader. For file URLs, it contains in addition whether the referenced file exists, is a valid JAR file, or is a directory. <p>NOTE: This method makes a best effort to provide information about the classloader, and never throws an exception. <p>NOTE: Passing {@code ClassLoader.getSystemClassLoader()} on Java 9+ will not return anything interesting. @param loader The classloader to get the info string for. @return The classloader information string.
getUserCodeClassLoaderInfo
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/ClassLoaderUtil.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/ClassLoaderUtil.java
Apache-2.0
public static String formatURL(URL url) throws IOException { StringBuilder bld = new StringBuilder(); bld.append("\n "); if (url == null) { bld.append("(null)"); } else if ("file".equals(url.getProtocol())) { String filePath = url.getPath(); File fileFile = new File(filePath); bld.append("file: '").append(filePath).append('\''); if (fileFile.exists()) { if (fileFile.isDirectory()) { bld.append(" (directory)"); } else { JarFile jar = null; try { jar = new JarFile(filePath); bld.append(" (valid JAR)"); } catch (Exception e) { bld.append(" (invalid JAR: ").append(e.getMessage()).append(')'); } finally { if (jar != null) { jar.close(); } } } } else { bld.append(" (missing)"); } } else { bld.append("url: ").append(url); } return bld.toString(); }
Returns the interpretation of URL in string format. <p>If the URL is null, it returns '(null)'. <p>If the URL protocol is file, prepend 'file:' flag before the formatted URL. Otherwise, use 'url: ' as the prefix instead. <p>Also, it checks whether the object that the URL directs to exists or not. If the object exists, some additional checks should be performed in order to determine that the object is a directory or a valid/invalid jar file. If the object does not exist, a missing flag should be appended. @param url URL that should be formatted @return The formatted URL @throws IOException When JarFile cannot be closed
formatURL
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/ClassLoaderUtil.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/ClassLoaderUtil.java
Apache-2.0
public static boolean validateClassLoadable(ClassNotFoundException cnfe, ClassLoader cl) { try { String className = cnfe.getMessage(); Class.forName(className, false, cl); return true; } catch (ClassNotFoundException e) { return false; } catch (Exception e) { return false; } }
Checks, whether the class that was not found in the given exception, can be resolved through the given class loader. @param cnfe The ClassNotFoundException that defines the name of the class. @param cl The class loader to use for the class resolution. @return True, if the class can be resolved with the given class loader, false if not.
validateClassLoadable
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/ClassLoaderUtil.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/ClassLoaderUtil.java
Apache-2.0
public static boolean isNullOrEmpty(Collection<?> collection) { return collection == null || collection.isEmpty(); }
Returns true if the given collection is null or empty.
isNullOrEmpty
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/CollectionUtil.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/CollectionUtil.java
Apache-2.0
public static <E> List<E> iterableToList(@Nullable Iterable<E> iterable) { if (iterable == null) { return Collections.emptyList(); } final ArrayList<E> list = new ArrayList<>(); iterable.iterator().forEachRemaining(list::add); return list; }
Collects the elements in the Iterable in a List. If the iterable argument is null, this method returns an empty list.
iterableToList
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/CollectionUtil.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/CollectionUtil.java
Apache-2.0
public static <E> List<E> iteratorToList(@Nullable Iterator<E> iterator) { if (iterator == null) { return Collections.emptyList(); } final ArrayList<E> list = new ArrayList<>(); iterator.forEachRemaining(list::add); return list; }
Collects the elements in the Iterator in a List. If the iterator argument is null, this method returns an empty list.
iteratorToList
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/CollectionUtil.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/CollectionUtil.java
Apache-2.0
public static <K, V> Map.Entry<K, V> entry(K k, V v) { return new AbstractMap.SimpleImmutableEntry<>(k, v); }
Returns an immutable {@link Map.Entry}.
entry
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/CollectionUtil.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/CollectionUtil.java
Apache-2.0
@SafeVarargs public static <K, V> Map<K, V> map(Map.Entry<K, V>... entries) { if (entries == null) { return Collections.emptyMap(); } Map<K, V> map = new HashMap<>(); for (Map.Entry<K, V> entry : entries) { map.put(entry.getKey(), entry.getValue()); } return Collections.unmodifiableMap(map); }
Returns an immutable {@link Map} from the provided entries.
map
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/CollectionUtil.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/CollectionUtil.java
Apache-2.0
public static <K, V> HashMap<K, V> newHashMapWithExpectedSize(int expectedSize) { return new HashMap<>( computeRequiredCapacity(expectedSize, HASH_MAP_DEFAULT_LOAD_FACTOR), HASH_MAP_DEFAULT_LOAD_FACTOR); }
Creates a new {@link HashMap} of the expected size, i.e. a hash map that will not rehash if expectedSize many keys are inserted, considering the load factor. @param expectedSize the expected size of the created hash map. @return a new hash map instance with enough capacity for the expected size. @param <K> the type of keys maintained by this map. @param <V> the type of mapped values.
newHashMapWithExpectedSize
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/CollectionUtil.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/CollectionUtil.java
Apache-2.0
public static <K, V> LinkedHashMap<K, V> newLinkedHashMapWithExpectedSize(int expectedSize) { return new LinkedHashMap<>( computeRequiredCapacity(expectedSize, HASH_MAP_DEFAULT_LOAD_FACTOR), HASH_MAP_DEFAULT_LOAD_FACTOR); }
Creates a new {@link LinkedHashMap} of the expected size, i.e. a hash map that will not rehash if expectedSize many keys are inserted, considering the load factor. @param expectedSize the expected size of the created hash map. @return a new hash map instance with enough capacity for the expected size. @param <K> the type of keys maintained by this map. @param <V> the type of mapped values.
newLinkedHashMapWithExpectedSize
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/CollectionUtil.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/CollectionUtil.java
Apache-2.0
public static <E> HashSet<E> newHashSetWithExpectedSize(int expectedSize) { return new HashSet<>( computeRequiredCapacity(expectedSize, HASH_MAP_DEFAULT_LOAD_FACTOR), HASH_MAP_DEFAULT_LOAD_FACTOR); }
Creates a new {@link HashSet} of the expected size, i.e. a hash set that will not rehash if expectedSize many unique elements are inserted, considering the load factor. @param expectedSize the expected size of the created hash map. @return a new hash map instance with enough capacity for the expected size. @param <E> the type of elements stored by this set.
newHashSetWithExpectedSize
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/CollectionUtil.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/CollectionUtil.java
Apache-2.0
public static <E> LinkedHashSet<E> newLinkedHashSetWithExpectedSize(int expectedSize) { return new LinkedHashSet<>( computeRequiredCapacity(expectedSize, HASH_MAP_DEFAULT_LOAD_FACTOR), HASH_MAP_DEFAULT_LOAD_FACTOR); }
Creates a new {@link LinkedHashSet} of the expected size, i.e. a hash set that will not rehash if expectedSize many unique elements are inserted, considering the load factor. @param expectedSize the expected size of the created hash map. @return a new hash map instance with enough capacity for the expected size. @param <E> the type of elements stored by this set.
newLinkedHashSetWithExpectedSize
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/CollectionUtil.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/CollectionUtil.java
Apache-2.0
@VisibleForTesting static int computeRequiredCapacity(int expectedSize, float loadFactor) { Preconditions.checkArgument(expectedSize >= 0); Preconditions.checkArgument(loadFactor > 0f); if (expectedSize <= 2) { return expectedSize + 1; } return expectedSize < (Integer.MAX_VALUE / 2 + 1) ? (int) Math.ceil(expectedSize / loadFactor) : Integer.MAX_VALUE; }
Helper method to compute the right capacity for a hash map with load factor HASH_MAP_DEFAULT_LOAD_FACTOR.
computeRequiredCapacity
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/CollectionUtil.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/CollectionUtil.java
Apache-2.0
public static <T> Collection<T> subTypeCast(Collection<? super T> collection) { @SuppressWarnings("unchecked") Collection<T> result = (Collection<T>) collection; return result; }
Casts the given collection to a subtype. This is an unchecked cast that can lead to runtime exceptions. @param collection the collection to cast. @return the collection unchecked-cast to a subtype. @param <T> the subtype to cast to.
subTypeCast
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/CollectionUtil.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/CollectionUtil.java
Apache-2.0
public static <T> Collection<T> checkedSubTypeCast( Collection<? super T> collection, Class<T> subTypeClass) { for (Object o : collection) { // probe each object, will throw ClassCastException on mismatch. subTypeClass.cast(o); } return subTypeCast(collection); }
Casts the given collection to a subtype. This is a checked cast. @param collection the collection to cast. @param subTypeClass the class of the subtype to cast to. @return the collection checked and cast to a subtype. @param <T> the subtype to cast to.
checkedSubTypeCast
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/CollectionUtil.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/CollectionUtil.java
Apache-2.0
@Override public T deserializeValue(ClassLoader loader) throws IOException, ClassNotFoundException { Preconditions.checkNotNull(loader, "No classloader has been passed"); return InstantiationUtil.decompressAndDeserializeObject(getByteArray(), loader); }
Decompress and deserialize the data to get the original object. @param loader the classloader to deserialize @return the deserialized object @throws IOException exception during decompression and deserialization @throws ClassNotFoundException if class is not found in the classloader
deserializeValue
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/CompressedSerializedValue.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/CompressedSerializedValue.java
Apache-2.0
public int getSize() { return getByteArray().length; }
Returns the size of the compressed serialized data.
getSize
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/CompressedSerializedValue.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/CompressedSerializedValue.java
Apache-2.0
public static <T> CompressedSerializedValue<T> fromObject(T object) throws IOException { Preconditions.checkNotNull(object, "Value must not be null"); return new CompressedSerializedValue<>(object); }
Constructs a compressed serialized value for the given object. @param object the object to serialize and compress @throws NullPointerException if object is null @throws IOException exception during serialization and compression
fromObject
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/CompressedSerializedValue.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/CompressedSerializedValue.java
Apache-2.0
public static String stringifyException(final Throwable e) { if (e == null) { return STRINGIFIED_NULL_EXCEPTION; } try { StringWriter stm = new StringWriter(); PrintWriter wrt = new PrintWriter(stm); e.printStackTrace(wrt); wrt.close(); return stm.toString(); } catch (Throwable t) { return e.getClass().getName() + " (error while printing stack trace)"; } }
Makes a string representation of the exception's stack trace, or "(null)", if the exception is null. <p>This method makes a best effort and never fails. @param e The exception to stringify. @return A string with exception name and call stack.
stringifyException
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
Apache-2.0
public static boolean isJvmFatalError(Throwable t) { return (t instanceof InternalError) || (t instanceof UnknownError) || (t instanceof ThreadDeath); }
Checks whether the given exception indicates a situation that may leave the JVM in a corrupted state, meaning a state where continued normal operation can only be guaranteed via clean process restart. <p>Currently considered fatal exceptions are Virtual Machine errors indicating that the JVM is corrupted, like {@link InternalError}, {@link UnknownError}, and {@link java.util.zip.ZipError} (a special case of InternalError). The {@link ThreadDeath} exception is also treated as a fatal error, because when a thread is forcefully stopped, there is a high chance that parts of the system are in an inconsistent state. @param t The exception to check. @return True, if the exception is considered fatal to the JVM, false otherwise.
isJvmFatalError
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
Apache-2.0
public static boolean isJvmFatalOrOutOfMemoryError(Throwable t) { return isJvmFatalError(t) || t instanceof OutOfMemoryError; }
Checks whether the given exception indicates a situation that may leave the JVM in a corrupted state, or an out-of-memory error. <p>See {@link ExceptionUtils#isJvmFatalError(Throwable)} for a list of fatal JVM errors. This method additionally classifies the {@link OutOfMemoryError} as fatal, because it may occur in any thread (not the one that allocated the majority of the memory) and thus is often not recoverable by destroying the particular thread that threw the exception. @param t The exception to check. @return True, if the exception is fatal to the JVM or and OutOfMemoryError, false otherwise.
isJvmFatalOrOutOfMemoryError
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
Apache-2.0
public static void tryEnrichOutOfMemoryError( @Nullable Throwable root, @Nullable String jvmMetaspaceOomNewErrorMessage, @Nullable String jvmDirectOomNewErrorMessage, @Nullable String jvmHeapSpaceOomNewErrorMessage) { updateDetailMessage( root, t -> { if (isMetaspaceOutOfMemoryError(t)) { return jvmMetaspaceOomNewErrorMessage; } else if (isDirectOutOfMemoryError(t)) { return jvmDirectOomNewErrorMessage; } else if (isHeapSpaceOutOfMemoryError(t)) { return jvmHeapSpaceOomNewErrorMessage; } return null; }); }
Tries to enrich OutOfMemoryErrors being part of the passed root Throwable's cause tree. <p>This method improves error messages for direct and metaspace {@link OutOfMemoryError}. It adds description about the possible causes and ways of resolution. @param root The Throwable of which the cause tree shall be traversed. @param jvmMetaspaceOomNewErrorMessage The message being used for JVM metaspace-related OutOfMemoryErrors. Passing <code>null</code> will disable handling this class of error. @param jvmDirectOomNewErrorMessage The message being used for direct memory-related OutOfMemoryErrors. Passing <code>null</code> will disable handling this class of error. @param jvmHeapSpaceOomNewErrorMessage The message being used for Heap space-related OutOfMemoryErrors. Passing <code>null</code> will disable handling this class of error.
tryEnrichOutOfMemoryError
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
Apache-2.0
public static boolean isMetaspaceOutOfMemoryError(@Nullable Throwable t) { return isOutOfMemoryErrorWithMessageContaining(t, "Metaspace"); }
Checks whether the given exception indicates a JVM metaspace out-of-memory error. @param t The exception to check. @return True, if the exception is the metaspace {@link OutOfMemoryError}, false otherwise.
isMetaspaceOutOfMemoryError
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
Apache-2.0
public static void rethrowIfFatalError(Throwable t) { if (isJvmFatalError(t)) { throw (Error) t; } }
Rethrows the given {@code Throwable}, if it represents an error that is fatal to the JVM. See {@link ExceptionUtils#isJvmFatalError(Throwable)} for a definition of fatal errors. @param t The Throwable to check and rethrow.
rethrowIfFatalError
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
Apache-2.0
public static void rethrowIfFatalErrorOrOOM(Throwable t) { if (isJvmFatalError(t) || t instanceof OutOfMemoryError) { throw (Error) t; } }
Rethrows the given {@code Throwable}, if it represents an error that is fatal to the JVM or an out-of-memory error. See {@link ExceptionUtils#isJvmFatalError(Throwable)} for a definition of fatal errors. @param t The Throwable to check and rethrow.
rethrowIfFatalErrorOrOOM
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
Apache-2.0
public static <T extends Throwable> T firstOrSuppressed(T newException, @Nullable T previous) { checkNotNull(newException, "newException"); if (previous == null || previous == newException) { return newException; } else { previous.addSuppressed(newException); return previous; } }
Adds a new exception as a {@link Throwable#addSuppressed(Throwable) suppressed exception} to a prior exception, or returns the new exception, if no prior exception exists. <pre>{@code public void closeAllThings() throws Exception { Exception ex = null; try { component.shutdown(); } catch (Exception e) { ex = firstOrSuppressed(e, ex); } try { anotherComponent.stop(); } catch (Exception e) { ex = firstOrSuppressed(e, ex); } try { lastComponent.shutdown(); } catch (Exception e) { ex = firstOrSuppressed(e, ex); } if (ex != null) { throw ex; } } }</pre> @param newException The newly occurred exception @param previous The previously occurred exception, possibly null. @return The new exception, if no previous exception exists, or the previous exception with the new exception in the list of suppressed exceptions.
firstOrSuppressed
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
Apache-2.0
public static void rethrow(Throwable t, String parentMessage) { if (t instanceof Error) { throw (Error) t; } else if (t instanceof RuntimeException) { throw (RuntimeException) t; } else { throw new RuntimeException(parentMessage, t); } }
Throws the given {@code Throwable} in scenarios where the signatures do not allow you to throw an arbitrary Throwable. Errors and RuntimeExceptions are thrown directly, other exceptions are packed into a parent RuntimeException. @param t The throwable to be thrown. @param parentMessage The message for the parent RuntimeException, if one is needed.
rethrow
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
Apache-2.0
public static void rethrowException(Throwable t, String parentMessage) throws Exception { if (t instanceof Error) { throw (Error) t; } else if (t instanceof Exception) { throw (Exception) t; } else { throw new Exception(parentMessage, t); } }
Throws the given {@code Throwable} in scenarios where the signatures do allow to throw a Exception. Errors and Exceptions are thrown directly, other "exotic" subclasses of Throwable are wrapped in an Exception. @param t The throwable to be thrown. @param parentMessage The message for the parent Exception, if one is needed.
rethrowException
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
Apache-2.0
public static void rethrowException(Throwable t) throws Exception { if (t instanceof Error) { throw (Error) t; } else if (t instanceof Exception) { throw (Exception) t; } else { throw new Exception(t.getMessage(), t); } }
Throws the given {@code Throwable} in scenarios where the signatures do allow to throw a Exception. Errors and Exceptions are thrown directly, other "exotic" subclasses of Throwable are wrapped in an Exception. @param t The throwable to be thrown.
rethrowException
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
Apache-2.0
public static void tryRethrowException(@Nullable Exception e) throws Exception { if (e != null) { throw e; } }
Tries to throw the given exception if not null. @param e exception to throw if not null. @throws Exception
tryRethrowException
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
Apache-2.0
public static void tryRethrowIOException(Throwable t) throws IOException { if (t instanceof IOException) { throw (IOException) t; } else if (t instanceof RuntimeException) { throw (RuntimeException) t; } else if (t instanceof Error) { throw (Error) t; } }
Tries to throw the given {@code Throwable} in scenarios where the signatures allows only IOExceptions (and RuntimeException and Error). Throws this exception directly, if it is an IOException, a RuntimeException, or an Error. Otherwise does nothing. @param t The Throwable to be thrown.
tryRethrowIOException
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
Apache-2.0
public static void rethrowIOException(Throwable t) throws IOException { if (t instanceof IOException) { throw (IOException) t; } else if (t instanceof RuntimeException) { throw (RuntimeException) t; } else if (t instanceof Error) { throw (Error) t; } else { throw new IOException(t.getMessage(), t); } }
Re-throws the given {@code Throwable} in scenarios where the signatures allows only IOExceptions (and RuntimeException and Error). <p>Throws this exception directly, if it is an IOException, a RuntimeException, or an Error. Otherwise it wraps it in an IOException and throws it. @param t The Throwable to be thrown.
rethrowIOException
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
Apache-2.0
public static <T extends Throwable> Optional<T> findSerializedThrowable( Throwable throwable, Class<T> searchType, ClassLoader classLoader) { if (throwable == null || searchType == null) { return Optional.empty(); } Throwable t = throwable; while (t != null) { if (searchType.isAssignableFrom(t.getClass())) { return Optional.of(searchType.cast(t)); } else if (t.getClass().isAssignableFrom(SerializedThrowable.class)) { Throwable next = ((SerializedThrowable) t).deserializeError(classLoader); // SerializedThrowable#deserializeError returns itself under some conditions (e.g., // null cause). // If that happens, exit to avoid looping infinitely. This is ok because if the user // was searching // for a SerializedThrowable, we would have returned it in the initial if condition. t = (next == t) ? null : next; } else { t = t.getCause(); } } return Optional.empty(); }
Checks whether a throwable chain contains a specific type of exception and returns it. It deserializes any {@link SerializedThrowable} that are found using the provided {@link ClassLoader}. @param throwable the throwable chain to check. @param searchType the type of exception to search for in the chain. @param classLoader to use for deserialization. @return Optional throwable of the requested type if available, otherwise empty
findSerializedThrowable
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
Apache-2.0
public static <T extends Throwable> Optional<T> findThrowable( Throwable throwable, Class<T> searchType) { if (throwable == null || searchType == null) { return Optional.empty(); } Throwable t = throwable; while (t != null) { if (searchType.isAssignableFrom(t.getClass())) { return Optional.of(searchType.cast(t)); } else { t = t.getCause(); } } return Optional.empty(); }
Checks whether a throwable chain contains a specific type of exception and returns it. @param throwable the throwable chain to check. @param searchType the type of exception to search for in the chain. @return Optional throwable of the requested type if available, otherwise empty
findThrowable
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
Apache-2.0
public static <T extends Throwable> void assertThrowable( Throwable throwable, Class<T> searchType) throws T { if (!findThrowable(throwable, searchType).isPresent()) { throw (T) throwable; } }
The same as {@link #findThrowable(Throwable, Class)}, but rethrows original exception if the expected exception was not found.
assertThrowable
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
Apache-2.0
public static <T extends Throwable> Optional<T> findThrowableSerializedAware( Throwable throwable, Class<T> searchType, ClassLoader classLoader) { if (throwable == null || searchType == null) { return Optional.empty(); } Throwable t = throwable; while (t != null) { if (searchType.isAssignableFrom(t.getClass())) { return Optional.of(searchType.cast(t)); } else if (t instanceof SerializedThrowable) { t = ((SerializedThrowable) t).deserializeError(classLoader); } else { t = t.getCause(); } } return Optional.empty(); }
Checks whether a throwable chain contains a specific type of exception and returns it. This method handles {@link SerializedThrowable}s in the chain and deserializes them with the given ClassLoader. <p>SerializedThrowables are often used when exceptions might come from dynamically loaded code and be transported over RPC / HTTP for better error reporting. The receiving processes or threads might not have the dynamically loaded code available. @param throwable the throwable chain to check. @param searchType the type of exception to search for in the chain. @param classLoader the ClassLoader to use when encountering a SerializedThrowable. @return Optional throwable of the requested type if available, otherwise empty
findThrowableSerializedAware
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
Apache-2.0
public static Optional<Throwable> findThrowable( Throwable throwable, Predicate<Throwable> predicate) { if (throwable == null || predicate == null) { return Optional.empty(); } Throwable t = throwable; while (t != null) { if (predicate.test(t)) { return Optional.of(t); } else { t = t.getCause(); } } return Optional.empty(); }
Checks whether a throwable chain contains an exception matching a predicate and returns it. @param throwable the throwable chain to check. @param predicate the predicate of the exception to search for in the chain. @return Optional throwable of the requested type if available, otherwise empty
findThrowable
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
Apache-2.0
public static <T extends Throwable> void assertThrowable( T throwable, Predicate<Throwable> predicate) throws T { if (!findThrowable(throwable, predicate).isPresent()) { throw (T) throwable; } }
The same as {@link #findThrowable(Throwable, Predicate)}, but rethrows original exception if the expected exception was not found.
assertThrowable
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
Apache-2.0
public static Optional<Throwable> findThrowableWithMessage( Throwable throwable, String searchMessage) { if (throwable == null || searchMessage == null) { return Optional.empty(); } Throwable t = throwable; while (t != null) { if (t.getMessage() != null && t.getMessage().contains(searchMessage)) { return Optional.of(t); } else { t = t.getCause(); } } return Optional.empty(); }
Checks whether a throwable chain contains a specific error message and returns the corresponding throwable. @param throwable the throwable chain to check. @param searchMessage the error message to search for in the chain. @return Optional throwable containing the search message if available, otherwise empty
findThrowableWithMessage
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
Apache-2.0
public static <T extends Throwable> void assertThrowableWithMessage( Throwable throwable, String searchMessage) throws T { if (!findThrowableWithMessage(throwable, searchMessage).isPresent()) { throw (T) throwable; } }
The same as {@link #findThrowableWithMessage(Throwable, String)}, but rethrows original exception if the expected exception was not found.
assertThrowableWithMessage
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
Apache-2.0
public static Throwable stripExecutionException(Throwable throwable) { return stripException(throwable, ExecutionException.class); }
Unpacks an {@link ExecutionException} and returns its cause. Otherwise the given Throwable is returned. @param throwable to unpack if it is an ExecutionException @return Cause of ExecutionException or given Throwable
stripExecutionException
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
Apache-2.0
public static Throwable stripCompletionException(Throwable throwable) { return stripException(throwable, CompletionException.class); }
Unpacks an {@link CompletionException} and returns its cause. Otherwise the given Throwable is returned. @param throwable to unpack if it is an CompletionException @return Cause of CompletionException or given Throwable
stripCompletionException
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
Apache-2.0
public static Throwable stripException( Throwable throwableToStrip, Class<? extends Throwable> typeToStrip) { while (typeToStrip.isAssignableFrom(throwableToStrip.getClass()) && throwableToStrip.getCause() != null) { throwableToStrip = throwableToStrip.getCause(); } return throwableToStrip; }
Unpacks an specified exception and returns its cause. Otherwise the given {@link Throwable} is returned. @param throwableToStrip to strip @param typeToStrip type to strip @return Unpacked cause or given Throwable if not packed
stripException
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
Apache-2.0
public static void tryDeserializeAndThrow(Throwable throwable, ClassLoader classLoader) throws Throwable { Throwable current = throwable; while (!(current instanceof SerializedThrowable) && current.getCause() != null) { current = current.getCause(); } if (current instanceof SerializedThrowable) { throw ((SerializedThrowable) current).deserializeError(classLoader); } else { throw throwable; } }
Tries to find a {@link SerializedThrowable} as the cause of the given throwable and throws its deserialized value. If there is no such throwable, then the original throwable is thrown. @param throwable to check for a SerializedThrowable @param classLoader to be used for the deserialization of the SerializedThrowable @throws Throwable either the deserialized throwable or the given throwable
tryDeserializeAndThrow
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
Apache-2.0
public static void checkInterrupted(Throwable e) { if (e instanceof InterruptedException) { Thread.currentThread().interrupt(); } }
Checks whether the given exception is a {@link InterruptedException} and sets the interrupted flag accordingly. @param e to check whether it is an {@link InterruptedException}
checkInterrupted
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
Apache-2.0
public static Throwable returnExceptionIfUnexpected(Throwable e) { return e instanceof FlinkExpectedException ? null : e; }
Return the given exception if it is not a {@link FlinkExpectedException}. @param e the given exception @return the given exception if it is not a {@link FlinkExpectedException}
returnExceptionIfUnexpected
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
Apache-2.0
public static List<Runnable> gracefulShutdown( long timeout, TimeUnit unit, ExecutorService... executorServices) { for (ExecutorService executorService : executorServices) { executorService.shutdown(); } boolean wasInterrupted = false; final long endTime = unit.toMillis(timeout) + System.currentTimeMillis(); long timeLeft = unit.toMillis(timeout); boolean hasTimeLeft = timeLeft > 0L; final List<Runnable> outstandingTasks = new ArrayList<>(); for (ExecutorService executorService : executorServices) { if (wasInterrupted || !hasTimeLeft) { outstandingTasks.addAll(executorService.shutdownNow()); } else { try { if (!executorService.awaitTermination(timeLeft, TimeUnit.MILLISECONDS)) { LOG.warn( "ExecutorService did not terminate in time. Shutting it down now."); outstandingTasks.addAll(executorService.shutdownNow()); } } catch (InterruptedException e) { LOG.warn( "Interrupted while shutting down executor services. Shutting all " + "remaining ExecutorServices down now.", e); outstandingTasks.addAll(executorService.shutdownNow()); wasInterrupted = true; Thread.currentThread().interrupt(); } timeLeft = endTime - System.currentTimeMillis(); hasTimeLeft = timeLeft > 0L; } } return outstandingTasks; }
Gracefully shutdown the given {@link ExecutorService}. The call waits the given timeout that all ExecutorServices terminate. If the ExecutorServices do not terminate in this time, they will be shut down hard. @param timeout to wait for the termination of all ExecutorServices @param unit of the timeout @param executorServices to shut down @return Tasks that were not executed prior to a {@link ExecutorService#shutdownNow()}.
gracefulShutdown
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/ExecutorUtils.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/ExecutorUtils.java
Apache-2.0
public static CompletableFuture<Void> nonBlockingShutdown( long timeout, TimeUnit unit, ExecutorService... executorServices) { return CompletableFuture.supplyAsync( () -> { gracefulShutdown(timeout, unit, executorServices); return null; }); }
Shuts the given {@link ExecutorService} down in a non-blocking fashion. The shut down will be executed by a thread from the common fork-join pool. <p>The executor services will be shut down gracefully for the given timeout period. Afterwards {@link ExecutorService#shutdownNow()} will be called. @param timeout before {@link ExecutorService#shutdownNow()} is called @param unit time unit of the timeout @param executorServices to shut down @return Future which is completed once the {@link ExecutorService} are shut down
nonBlockingShutdown
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/ExecutorUtils.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/ExecutorUtils.java
Apache-2.0
@Override public void uncaughtException(Thread t, Throwable e) { try { LOG.error( "FATAL: Thread '{}' produced an uncaught exception. Stopping the process...", t.getName(), e); ThreadUtils.errorLogThreadDump(LOG); } finally { FlinkSecurityManager.forceProcessExit(EXIT_CODE); } }
Handler for uncaught exceptions that will log the exception and kill the process afterwards. <p>This guarantees that critical exceptions are not accidentally lost and leave the system running in an inconsistent state.
uncaughtException
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/FatalExitExceptionHandler.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/FatalExitExceptionHandler.java
Apache-2.0
public static FileLock inTempFolder(String fileName) { return new FileLock(TEMP_DIR, fileName); }
Initialize a FileLock using a file located inside temp folder. @param fileName The name of the locking file @return The initialized FileLock
inTempFolder
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/FileLock.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/FileLock.java
Apache-2.0
private void init() throws IOException { if (!this.file.exists()) { this.file.createNewFile(); } outputStream = new FileOutputStream(this.file); }
Check whether the locking file exists in the file system. Create it if it does not exist. Then create a FileOutputStream for it. @throws IOException If the file path is invalid or the parent dir does not exist
init
java
apache/flink
flink-core/src/main/java/org/apache/flink/util/FileLock.java
https://github.com/apache/flink/blob/master/flink-core/src/main/java/org/apache/flink/util/FileLock.java
Apache-2.0