code
stringlengths
73
34.1k
label
stringclasses
1 value
public final Timestamp addDay(int amount) { long delta = (long) amount * 24 * 60 * 60 * 1000; return addMillisForPrecision(delta, Precision.DAY, false); }
java
public static void printStringCodePoint(Appendable out, int codePoint) throws IOException { printCodePoint(out, codePoint, EscapeMode.ION_STRING); }
java
public static void printSymbolCodePoint(Appendable out, int codePoint) throws IOException { printCodePoint(out, codePoint, EscapeMode.ION_SYMBOL); }
java
public static void printJsonCodePoint(Appendable out, int codePoint) throws IOException { // JSON only allows double-quote strings. printCodePoint(out, codePoint, EscapeMode.JSON); }
java
private static void printCodePoint(Appendable out, int c, EscapeMode mode) throws IOException { // JSON only allows uHHHH numeric escapes. switch (c) { case 0: out.append(mode == EscapeMode.JSON ? "\\u0000" : "\\0"); return; case '\t': ...
java
public static String printCodePointAsString(int codePoint) { StringBuilder builder = new StringBuilder(12); builder.append('"'); try { printStringCodePoint(builder, codePoint); } catch (IOException e) { // Shouldn't happen t...
java
public void truncate(final long position) { final int index = index(position); final int offset = offset(position); final Block block = blocks.get(index); this.index = index; block.limit = offset; current = block; }
java
public int getUInt8At(final long position) { final int index = index(position); final int offset = offset(position); final Block block = blocks.get(index); return block.data[offset] & OCTET_MASK; }
java
public void writeByte(final byte octet) { if (remaining() < 1) { if (index == blocks.size() - 1) { allocateNewBlock(); } index++; current = blocks.get(index); } final Block block = current; block.data...
java
private void writeBytesSlow(final byte[] bytes, int off, int len) { while (len > 0) { final Block block = current; final int amount = Math.min(len, block.remaining()); System.arraycopy(bytes, off, block.data, block.limit, amount); block.limit += amount...
java
public void writeBytes(final byte[] bytes, final int off, final int len) { if (len > remaining()) { writeBytesSlow(bytes, off, len); return; } final Block block = current; System.arraycopy(bytes, off, block.data, block.limit, len); block.limit...
java
private int writeUTF8Slow(final CharSequence chars, int off, int len) { int octets = 0; while (len > 0) { final char ch = chars.charAt(off); if (ch >= LOW_SURROGATE_FIRST && ch <= LOW_SURROGATE_LAST) { throw new IllegalArgumentException("Un...
java
public void writeTo(final OutputStream out) throws IOException { for (int i = 0; i <= index; i++) { Block block = blocks.get(i); out.write(block.data, 0, block.limit); } }
java
public void writeTo(final OutputStream out, long position, long length) throws IOException { while (length > 0) { final int index = index(position); final int offset = offset(position); final Block block = blocks.get(index); final int amount = (int) Ma...
java
public static _Private_IonTextAppender forAppendable(Appendable out) { _Private_FastAppendable fast = new AppendableFastAppendable(out); boolean escapeNonAscii = false; return new _Private_IonTextAppender(fast, escapeNonAscii); }
java
public final void printString(CharSequence text) throws IOException { if (text == null) { appendAscii("null.string"); } else { appendAscii('"'); printCodePoints(text, STRING_ESCAPE_CODES); appendAscii('"'); } ...
java
public final void printLongString(CharSequence text) throws IOException { if (text == null) { appendAscii("null.string"); } else { appendAscii(TRIPLE_QUOTES); printCodePoints(text, LONG_STRING_ESCAPE_CODES); appendAscii(...
java
public final void printJsonString(CharSequence text) throws IOException { if (text == null) { appendAscii("null"); } else { appendAscii('"'); printCodePoints(text, JSON_ESCAPE_CODES); appendAscii('"'); } }
java
public final void printSymbol(CharSequence text) throws IOException { if (text == null) { appendAscii("null.symbol"); } else if (symbolNeedsQuoting(text, true)) { appendAscii('\''); printCodePoints(text, SYMBOL_ESCAPE_CODES); ap...
java
public final void printQuotedSymbol(CharSequence text) throws IOException { if (text == null) { appendAscii("null.symbol"); } else { appendAscii('\''); printCodePoints(text, SYMBOL_ESCAPE_CODES); appendAscii('\''); ...
java
@Override public SymbolTable getSymbolTable() { SymbolTable symtab = super.getSymbolTable(); if (symtab == null) { symtab = _system_symtab; } return symtab; }
java
public _Private_IonManagedBinaryWriterBuilder withFlatImports(final SymbolTable... tables) { if (tables != null) { return withFlatImports(Arrays.asList(tables)); } return this; }
java
public void writeValue(IonReader reader) throws IOException { // TODO this should do symtab optimization as per writeValues() IonType type = reader.getType(); writeValueRecursively(type, reader); }
java
boolean attemptClearSymbolIDValues() { boolean sidsRemain = false; if (_fieldName != null) { _fieldId = UNKNOWN_SYMBOL_ID; } else if (_fieldId > UNKNOWN_SYMBOL_ID) { // retaining the field SID, as it couldn't be cleared due to loss of context ...
java
final void setFieldNameSymbol(SymbolToken name) { assert _fieldId == UNKNOWN_SYMBOL_ID && _fieldName == null; _fieldName = name.getText(); _fieldId = name.getSid(); // if a SID has been added by this operation to a previously SID-less node we have to mark upwards // toward...
java
final void detachFromContainer() // throws IOException { checkForLock(); clearSymbolIDValues(); _context = ContainerlessContext.wrap(getSystem()); _fieldName = null; _fieldId = UNKNOWN_SYMBOL_ID; _elementid(0); }
java
public final static int convertToUTF8Bytes(int unicodeScalar, byte[] outputBytes, int offset, int maxLength) { int dst = offset; int end = offset + maxLength; switch (getUTF8ByteCount(unicodeScalar)) { case 1: if (dst >= end) throw new ArrayIndexOutOfBoundsException(); ...
java
public byte[] getBytes() { int length = _eob - _start; byte[] copy = new byte[length]; System.arraycopy(_bytes, _start, copy, 0, length); return copy; }
java
private void prepareValue() { if (isInStruct() && currentFieldSid == null) { throw new IllegalStateException("IonWriter.setFieldName() must be called before writing a value into a struct."); } if (currentFieldSid != null) { checkSid(currentFieldSid); ...
java
private void finishValue() { final ContainerInfo current = currentContainer(); if (current != null && current.type == ContainerType.ANNOTATION) { // close out and patch the length popContainer(); } hasWrittenValuesSinceFinished = true; hasWritt...
java
public static SymbolToken symbol(final String name, final int val) { if (name == null) { throw new NullPointerException(); } if (val <= 0) { throw new IllegalArgumentException("Symbol value must be positive: " + val); } return new SymbolToken() { public String getText() ...
java
public static Iterator<String> symbolNameIterator(final Iterator<SymbolToken> tokenIter) { return new Iterator<String>() { public boolean hasNext() { return tokenIter.hasNext(); } public String next() { retu...
java
public static SymbolToken systemSymbol(final int sid) { if (sid < 1 || sid > ION_1_0_MAX_ID) { throw new IllegalArgumentException("No such system SID: " + sid); } return SYSTEM_TOKENS.get(sid - 1); }
java
public static SymbolTable unknownSharedSymbolTable(final String name, final int version, final int maxId) { return new AbstractSymbolTable(name, version) { public Iterator<Strin...
java
public static void main(String[] args) throws IOException { process_command_line(args); info = new JarInfo(); if (printVersion) { doPrintVersion(); } if (printHelp) { doPrintHelp(); } }
java
@Deprecated public static IonSystem newSystem(IonCatalog catalog) { return IonSystemBuilder.standard().withCatalog(catalog).build(); }
java
protected void tokenValueIsFinished() { _scanner.tokenIsFinished(); if (IonType.BLOB.equals(_value_type) || IonType.CLOB.equals(_value_type)) { int state_after_scalar = get_state_after_value(); set_state(state_after_scalar); } }
java
public boolean isInStruct() { boolean in_struct = false; IonType container = getContainerType(); if (IonType.STRUCT.equals(container)) { if (getDepth() > 0) { in_struct = true; } else { assert(IonType.STRUCT.equals(_nesting_...
java
private boolean is_in_struct_internal() { boolean in_struct = false; IonType container = getContainerType(); if (IonType.STRUCT.equals(container)) { in_struct = true; } return in_struct; }
java
public long getPosition() { long file_pos = 0; UnifiedDataPageX page = _buffer.getCurrentPage(); if (page != null) { file_pos = page.getFilePosition(_pos); } return file_pos; }
java
public final int read(byte[] dst, int offset, int length) throws IOException { if (!is_byte_data()) { throw new IOException("byte read is not support over character sources"); } int remaining = length; while (remaining > 0 && !isEOF()) { int ready = _limit - _...
java
protected int refill() throws IOException { UnifiedDataPageX curr = _buffer.getCurrentPage(); SavePoint sp = _save_points.savePointActiveTop(); if (!can_fill_new_page()) { // aka: there can be only one! // (and it's used up) return refill_is_eof(); ...
java
private bbBlock init(int initialSize, bbBlock initialBlock) { this._lastCapacity = BlockedBuffer._defaultBlockSizeMin; this._blockSizeUpperLimit = BlockedBuffer._defaultBlockSizeUpperLimit; while (this._lastCapacity < initialSize && this._lastCapacity < this._blockSizeUpperLim...
java
private void clear(Object caller, int version) { assert mutation_in_progress(caller, version); _buf_limit = 0; for (int ii=0; ii<_blocks.size(); ii++) { _blocks.get(ii).clearBlock(); // _blocks.get(ii)._idx = -1; this is done in clearBlock() } bbBlock firs...
java
bbBlock truncate(Object caller, int version, int pos) { assert mutation_in_progress(caller, version); if (0 > pos || pos > this._buf_limit ) throw new IllegalArgumentException(); // clear out all the blocks in use from the last in use // to the block where the eof will be loc...
java
int insert(Object caller, int version, bbBlock curr, int pos, int len) { assert mutation_in_progress(caller, version); // DEBUG: int amountMoved = 0; // DEBUG: int before = this._buf_limit; // DEBUG: assert _validate(); // if there's room in the current block - just /...
java
private int insertInCurrOnly(Object caller, int version, bbBlock curr, int pos, int len) { assert mutation_in_progress(caller, version); // the space we need is available right in the block assert curr.unusedBlockCapacity() >= len; System.arraycopy(curr._buffer, curr.blockOffsetFromA...
java
private int readVarInt(int firstByte) throws IOException { // VarInt uses the high-order bit of the last octet as a marker; some (but not all) 5-byte VarInts can fit // into a Java int. // To validate overflows we accumulate the VarInt in a long and then check if it can be represented by an int ...
java
public Type next(boolean is_in_expression) throws IOException { inQuotedContent = false; int c = this.readIgnoreWhitespace(); return next(c, is_in_expression); }
java
private boolean twoMoreSingleQuotes() throws IOException { int c = read(); if (c == '\'') { int c2 = read(); if (c2 == '\'') { return true; } unread(c2); } unread(c); return false; }
java
public final static int typeNameKeyWordFromMask(int possible_names, int length) { int kw = KEYWORD_unrecognized; if (possible_names != IonTokenConstsX.KW_ALL_BITS) { for (int ii=0; ii<typeNameBits.length; ii++) { int tb = typeNameBits[ii]; if (tb == possible_n...
java
public final IonTextWriterBuilder withIvmMinimizing(IvmMinimizing minimizing) { IonTextWriterBuilder b = mutable(); b.setIvmMinimizing(minimizing); return b; }
java
public final IonTextWriterBuilder withLongStringThreshold(int threshold) { IonTextWriterBuilder b = mutable(); b.setLongStringThreshold(threshold); return b; }
java
private void startLocalSymbolTableIfNeeded(final boolean writeIVM) throws IOException { if (symbolState == SymbolState.SYSTEM_SYMBOLS) { if (writeIVM) { symbols.writeIonVersionMarker(); } symbols.addTypeAnnotationSymbol(systemSymbol(ION...
java
public void setFieldName(final String name) { if (!isInStruct()) { throw new IllegalStateException("IonWriter.setFieldName() must be called before writing a value into a struct."); } if (name == null) { throw new NullPointerException("Null field name i...
java
public SymbolTable removeTable(String name, int version) { SymbolTable removed = null; synchronized (myTablesByName) { TreeMap<Integer,SymbolTable> versions = myTablesByName.get(name); if (versions != null) { synchronized (...
java
public Iterator<SymbolTable> iterator() { ArrayList<SymbolTable> tables; synchronized (myTablesByName) { tables = new ArrayList<SymbolTable>(myTablesByName.size()); // I don't think we can shorten the synchronization block // because HashMap.values() res...
java
void validateNewChild(IonValue child) throws ContainedValueException, NullPointerException, IllegalArgumentException { if (child.getContainer() != null) // Also checks for null. { throw new ContainedValueException(); } if (child.isReadOn...
java
protected int add_child(int idx, IonValueLite child) { _isNullValue(false); // if we add children we're not null anymore child.setContext(this.getContextForIndex(child, idx)); if (_children == null || _child_count >= _children.length) { int old_len = (_children == null) ? 0 : _ch...
java
void remove_child(int idx) { assert(idx >=0); assert(idx < get_child_count()); // this also asserts child count > 0 assert get_child(idx) != null : "No child at index " + idx; _children[idx].detachFromContainer(); int children_to_move = _child_count - idx - 1; if (ch...
java
public void put(String fieldName, IonValue value) { checkForLock(); validateFieldName(fieldName); if (value != null) validateNewChild(value); int lowestRemovedIndex = get_child_count(); boolean any_removed = false; // first we remove the any existing fields ...
java
protected int lobHashCode(int seed, SymbolTableProvider symbolTableProvider) { int result = seed; if (!isNullValue()) { CRC32 crc = new CRC32(); crc.update(getBytes()); result ^= (int) crc.getValue(); } return hashTypeAnnotations(result, symbolT...
java
public final boolean skipDoubleColon() throws IOException { int c = skip_over_whitespace(); if (c != ':') { unread_char(c); return false; } c = read_char(); if (c != ':') { unread_char(c); unread_char(':'); return fa...
java
public final int peekNullTypeSymbol() throws IOException { // the '.' has to follow the 'null' immediately int c = read_char(); if (c != '.') { unread_char(c); return IonTokenConstsX.KEYWORD_none; } // we have a dot, start reading through the followin...
java
public final int peekLobStartPunctuation() throws IOException { int c = skip_over_lob_whitespace(); if (c == '"') { //unread_char(c); return IonTokenConstsX.TOKEN_STRING_DOUBLE_QUOTE; } if (c != '\'') { unread_char(c); return IonTokenCo...
java
protected final void skip_clob_close_punctuation() throws IOException { int c = skip_over_clob_whitespace(); if (c == '}') { c = read_char(); if (c == '}') { return; } unread_char(c); c = '}'; } unread_char(c); ...
java
private final boolean skip_whitespace(CommentStrategy commentStrategy) throws IOException { boolean any_whitespace = false; int c; loop: for (;;) { c = read_char(); switch (c) { case -1: break loop; case ' ': case '...
java
private final boolean is_2_single_quotes_helper() throws IOException { int c = read_char(); if (c != '\'') { unread_char(c); return false; } c = read_char(); if (c != '\'') { unread_char(c); unread_char('\''); return...
java
private final int scan_negative_for_numeric_type(int c) throws IOException { assert(c == '-'); c = read_char(); int t = scan_for_numeric_type(c); if (t == IonTokenConstsX.TOKEN_TIMESTAMP) { bad_token(c); } unread_char(c); // and the caller need to unread t...
java
protected void load_raw_characters(StringBuilder sb) throws IOException { int c = read_char(); for (;;) { c = read_char(); switch (c) { case CharacterSequence.CHAR_SEQ_ESCAPED_NEWLINE_SEQUENCE_1: case CharacterSequence.CHAR_SEQ_ESCAPED_NEWLINE_SEQUENCE...
java
private final int skip_timestamp_past_digits(int min, int max) throws IOException { int c; // scan the first min characters insuring they're digits while (min > 0) { c = read_char(); if (!IonTokenConstsX.isDigit(c)) { error("invalid character ...
java
private final int load_exponent(StringBuilder sb) throws IOException { int c = read_char(); if (c == '-' || c == '+') { sb.append((char)c); c = read_char(); } c = load_digits(sb, c); if (c == '.') { sb.append((char)c); c = read...
java
private final int load_digits(StringBuilder sb, int c) throws IOException { if (!IonTokenConstsX.isDigit(c)) { return c; } sb.append((char) c); return readNumeric(sb, Radix.DECIMAL, NumericState.DIGIT); }
java
protected void skip_over_lob(int lobToken, SavePoint sp) throws IOException { switch(lobToken) { case IonTokenConstsX.TOKEN_STRING_DOUBLE_QUOTE: skip_double_quoted_string(sp); skip_clob_close_punctuation(); break; case IonTokenConstsX.TOKEN_STRING_TRIPLE_QUOTE...
java
public void writeRaw(byte[] value, int start, int len) throws IOException { startValue(TID_RAW); _writer.write(value, start, len); _patch.patchValue(len); closeValue(); }
java
int writeBytes(OutputStream userstream) throws IOException { if (_patch.getParent() != null) { throw new IllegalStateException("Tried to flush while not on top-level"); } try { BlockedByteInputStream datastream = new BlockedByteInputStream(_manager.buffer...
java
private IonDatagramLite load_helper(IonReader reader) throws IOException { IonDatagramLite datagram = new IonDatagramLite(_system, _catalog); IonWriter writer = _Private_IonWriterFactory.makeWriter(datagram); writer.writeValues(reader); return datagram; }
java
IonStruct getIonRepresentation() { synchronized (this) { IonStruct image = myImage; if (image == null) { // Start a new image from scratch myImage = image = makeIonRepresentation(myImageFactory); } return i...
java
private IonStruct makeIonRepresentation(ValueFactory factory) { IonStruct ionRep = factory.newEmptyStruct(); ionRep.addTypeAnnotation(ION_SYMBOL_TABLE); SymbolTable[] importedTables = getImportedTablesNoCopy(); if (importedTables.length > 1) { IonList importsLi...
java
private void recordLocalSymbolInIonRep(IonStruct ionRep, String symbolName, int sid) { assert sid >= myFirstLocalSid; ValueFactory sys = ionRep.getSystem(); // TODO this is crazy inefficient and not as re...
java
@Override public int read() throws IOException { int nextChar = super.read(); // process the character if ( nextChar != -1 ) { if ( nextChar == '\n' ) { m_line++; pushColumn( m_column ); m_column = 0; } else...
java
private void unreadImpl(int c, boolean updateCounts ) throws IOException { if ( c != -1 ) { if ( updateCounts ) { if ( c == '\n' ) { m_line--; m_column = popColumn(); } else { m_column--; } ...
java
public static void verifyBinaryVersionMarker(Reader reader) throws IonException { try { int pos = reader.position(); //reader.sync(); //reader.setPosition(0); byte[] bvm = new byte[BINARY_VERSION_MARKER_SIZE]; int len = readFully(re...
java
public static int lenVarUInt(long longVal) { assert longVal >= 0; if (longVal < (1L << (7 * 1))) return 1; // 7 bits if (longVal < (1L << (7 * 2))) return 2; // 14 bits if (longVal < (1L << (7 * 3))) return 3; // 21 bits if (longVal < (1L << (7 * 4))) return 4; // 28 bits ...
java
public static int lenIonTimestamp(Timestamp di) { if (di == null) return 0; int len = 0; switch (di.getPrecision()) { case FRACTION: case SECOND: { BigDecimal fraction = di.getFractionalSecond(); if (fraction != null) { ...
java
private final int stateFirstInStruct() { int new_state; if (hasName()) { new_state = S_NAME; } else if (hasMaxId()) { new_state = S_MAX_ID; } else if (hasImports()) { new_state = S_IMPORT_LIST; } else if (hasLocalSy...
java
public IonType next() { if (has_next_helper() == false) { return null; } int new_state; switch (_current_state) { case S_BOF: new_state = S_STRUCT; break; case S_STRUCT: new_state = S_EOF; break; ...
java
private int growBuffer(int offset) { assert offset < 0; byte[] oldBuf = myBuffer; int oldLen = oldBuf.length; byte[] newBuf = new byte[(-offset + oldLen) << 1]; // Double the buffer int oldBegin = newBuf.length - oldLen; System.arraycopy(oldBuf, 0, newBuf, oldBegin, o...
java
private void writeIonValue(IonValue value) throws IonException { final int valueOffset = myBuffer.length - myOffset; switch (value.getType()) { // scalars case BLOB: writeIonBlobContent((IonBlob) value); break; case BOOL: writ...
java
private void writeSymbolsField(SymbolTable symTab) { // SymbolTable's APIs doesn't expose an Iterator to traverse declared // symbol strings in reverse order. As such, we utilize these two // indexes to traverse the strings in reverse. int importedMaxId = symTab.getImportedMaxId(); ...
java
private List<String> getPercolationMatches(JsonMetric jsonMetric) throws IOException { HttpURLConnection connection = openConnection("/" + currentIndexName + "/" + jsonMetric.type() + "/_percolate", "POST"); if (connection == null) { LOGGER.error("Could not connect to any configured elastics...
java
private void addJsonMetricToPercolationIfMatching(JsonMetric<? extends Metric> jsonMetric, List<JsonMetric> percolationMetrics) { if (percolationFilter != null && percolationFilter.matches(jsonMetric.name(), jsonMetric.value())) { percolationMetrics.add(jsonMetric); } }
java
private HttpURLConnection createNewConnectionIfBulkSizeReached(HttpURLConnection connection, int entriesWritten) throws IOException { if (entriesWritten % bulkSize == 0) { closeConnection(connection); return openConnection("/_bulk", "POST"); } return connection; }
java
private void writeJsonMetric(JsonMetric jsonMetric, ObjectWriter writer, OutputStream out) throws IOException { writer.writeValue(out, new BulkIndexOperationHeader(currentIndexName, jsonMetric.type())); out.write("\n".getBytes()); writer.writeValue(out, jsonMetric); out.write("\n".getByt...
java
private HttpURLConnection openConnection(String uri, String method) { for (String host : hosts) { try { URL templateUrl = new URL("http://" + host + uri); HttpURLConnection connection = ( HttpURLConnection ) templateUrl.openConnection(); connection.se...
java
private void checkForIndexTemplate() { try { HttpURLConnection connection = openConnection( "/_template/metrics_template", "HEAD"); if (connection == null) { LOGGER.error("Could not connect to any configured elasticsearch instances: {}", Arrays.asList(hosts)); ...
java
public void post(Notification event) { for (Map.Entry<Object, List<SubscriberMethod>> entry : listeners.entrySet()) { for (SubscriberMethod method : entry.getValue()) { if (method.eventTypeToInvokeOn.isInstance(event)) { try { method.method...
java
@Override public Void call(SQLDatabase db) throws DocumentStoreException { /* Pick winner and mark the appropriate revision with the 'current' flag set - There can only be one winner in a tree (or set of trees - if there is no common root) at any one time, so if there is a new...
java
public static byte[] encryptAES(SecretKey key, byte[] iv, byte[] unencryptedBytes) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException { Cipher aesCipher = Cipher.getInstance("AES...
java
public static byte[] decryptAES(SecretKey key, byte[] iv, byte[] encryptedBytes) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException { Cipher aesCipher = Cipher.getInstance("AES/C...
java