Search in sources :

Example 51 with IonException

use of com.amazon.ion.IonException in project ion-java by amzn.

the class IonTokenReader method scanTimestamp.

/**
 * Scans a timestamp after reading <code>yyyy-</code>.
 *
 * We can be a little lenient here since the result will be reparsed and
 * validated more thoroughly by {@link Timestamp#valueOf(CharSequence)}.
 *
 * @param c the last character scanned; must be <code>'-'</code>.
 * @return {@link Type#constTime}
 */
Type scanTimestamp(int c) throws IOException {
    endofdate: for (; ; ) {
        // in other words, we'll have read the year
        if (c == 'T') {
            // yearT is a valid timestamp value
            value.append((char) c);
            // because we'll unread it before we return
            c = this.read();
            break endofdate;
        }
        if (c != '-') {
            // not a dash or a T after the year - so this is a bad value
            throw new IllegalStateException("invalid timestamp, expecting a dash here at " + this.position());
        }
        // append the dash and then read the month field
        // so append it, because we haven't already
        value.append((char) c);
        c = readDigits(2, "month");
        if (c == 'T') {
            // year-monthT is a valid timestamp value
            value.append((char) c);
            // because we'll unread it before we return
            c = this.read();
            break endofdate;
        }
        if (c != '-') {
            // if the month isn't followed by a dash or a T it's an invalid month
            throw new IonException("invalid timestamp, expecting month at " + this.position());
        }
        // append the dash and read the day (or day-of-month) field
        value.append((char) c);
        c = readDigits(2, "day of month");
        if (c == 'T') {
            check4timezone: for (; ; ) {
                // another fake label/ for=goto
                // attach the 'T' to the value we're collecting
                value.append((char) c);
                // we're going to "watch" how many digits we read in the hours
                // field.  It's 0 that's actually ok, since we can end at the
                // 'T' we just read
                int length_before_reading_hours = value.length();
                // so read the hours
                c = readDigits(2, "hours");
                if (length_before_reading_hours == value.length()) {
                    // FIXME I don't think there should be a timezone here
                    break check4timezone;
                }
                if (c != ':') {
                    throw new IonException("invalid timestamp, expecting hours at " + this.position());
                }
                value.append((char) c);
                // so read the minutes
                c = readDigits(2, "minutes");
                if (c != ':') {
                    if (c == '-' || c == '+' || c == 'Z') {
                        break check4timezone;
                    }
                    break endofdate;
                }
                value.append((char) c);
                // so read the seconds
                c = readDigits(2, "seconds");
                if (c != '.') {
                    if (c == '-' || c == '+' || c == 'Z') {
                        break check4timezone;
                    }
                    break endofdate;
                }
                value.append((char) c);
                // so read the fractional seconds
                c = readDigits(32, "fractional seconds");
                break check4timezone;
            }
            // now check to see if it's a timezone offset we're looking at
            if (c == '-' || c == '+') {
                value.append((char) c);
                // so read the timezone offset
                c = readDigits(2, "timezone offset");
                if (c != ':')
                    break endofdate;
                value.append((char) c);
                c = readDigits(2, "timezone offset");
            } else if (c == 'Z') {
                value.append((char) c);
                // because we'll unread it before we return
                c = this.read();
            }
        }
        break endofdate;
    }
    // endofdate
    checkAndUnreadNumericStopper(c);
    return Type.constTime;
}
Also used : IonException(com.amazon.ion.IonException)

Example 52 with IonException

use of com.amazon.ion.IonException in project ion-java by amzn.

the class _Private_IonReaderBuilder method build.

@Override
public IonReader build(InputStream ionData) {
    InputStream wrapper = ionData;
    if (isIncrementalReadingEnabled()) {
        if (!ionData.markSupported()) {
            wrapper = new BufferedInputStream(ionData);
        }
        wrapper.mark(_Private_IonConstants.BINARY_VERSION_MARKER_SIZE);
        byte[] possibleIVM = new byte[_Private_IonConstants.BINARY_VERSION_MARKER_SIZE];
        int bytesRead;
        try {
            bytesRead = wrapper.read(possibleIVM);
            wrapper.reset();
        } catch (IOException e) {
            throw new IonException(e);
        }
        if (IonStreamUtils.isGzip(possibleIVM, 0, possibleIVM.length)) {
            throw new IllegalArgumentException("Automatic GZIP detection is not supported with incremental" + "support enabled. Wrap the bytes with a GZIPInputStream and call build(InputStream).");
        }
        // (which has always been unsupported).
        if (startsWithIvm(possibleIVM, bytesRead)) {
            return makeIncrementalReader(this, wrapper);
        }
    }
    return makeReader(validateCatalog(), wrapper, lstFactory);
}
Also used : BufferedInputStream(java.io.BufferedInputStream) IonException(com.amazon.ion.IonException) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 53 with IonException

use of com.amazon.ion.IonException in project ion-java by amzn.

the class IonWriterSystemText method closeValue.

void closeValue() throws IOException {
    super.endValue();
    _pending_separator = true;
    // Caller overwrites this as needed.
    _following_long_string = false;
    // Flush if a top-level-value was written
    if (getDepth() == 0) {
        try {
            flush();
        } catch (IOException e) {
            throw new IonException(e);
        }
    }
}
Also used : IonException(com.amazon.ion.IonException) IOException(java.io.IOException)

Example 54 with IonException

use of com.amazon.ion.IonException in project ion-java by amzn.

the class IonReaderTextRawX method get_state_after_container.

private final int get_state_after_container(int token) {
    IonType container = top_state();
    switch(container) {
        case STRUCT:
            check_container_close(container, TOKEN_CLOSE_BRACE, token);
            break;
        case LIST:
            check_container_close(container, TOKEN_CLOSE_SQUARE, token);
            break;
        case SEXP:
            check_container_close(container, TOKEN_CLOSE_PAREN, token);
            break;
        case DATAGRAM:
        // We shouldn't get here.  Fall through.
        default:
            String message = "invalid container type encountered during parsing " + container + _scanner.input_position();
            throw new IonException(message);
    }
    int new_state = get_state_after_container(container);
    return new_state;
}
Also used : IonType(com.amazon.ion.IonType) IonException(com.amazon.ion.IonException) SavePoint(com.amazon.ion.impl.UnifiedSavePointManagerX.SavePoint)

Example 55 with IonException

use of com.amazon.ion.IonException in project ion-java by amzn.

the class IonReaderTextRawX method has_next_raw_value.

protected final boolean has_next_raw_value() {
    if (!_has_next_called && !_eof) {
        try {
            finish_value(null);
            clear_value();
            parse_to_next_value();
        } catch (IOException e) {
            throw new IonException(e);
        }
        _has_next_called = true;
    }
    return (_eof != true);
}
Also used : IonException(com.amazon.ion.IonException) IOException(java.io.IOException)

Aggregations

IonException (com.amazon.ion.IonException)66 IOException (java.io.IOException)31 IonReader (com.amazon.ion.IonReader)10 IonType (com.amazon.ion.IonType)9 SymbolToken (com.amazon.ion.SymbolToken)9 IonValue (com.amazon.ion.IonValue)7 Event (com.amazon.tools.events.Event)7 Test (org.junit.Test)6 IonStruct (com.amazon.ion.IonStruct)5 SymbolTable (com.amazon.ion.SymbolTable)5 SavePoint (com.amazon.ion.impl.UnifiedSavePointManagerX.SavePoint)5 InputStream (java.io.InputStream)5 ArrayList (java.util.ArrayList)5 EventType (com.amazon.tools.events.EventType)4 IonWriter (com.amazon.ion.IonWriter)3 IonDatagram (com.amazon.ion.IonDatagram)2 IonLob (com.amazon.ion.IonLob)2 Timestamp (com.amazon.ion.Timestamp)2 BufferManager (com.amazon.ion.impl.IonBinary.BufferManager)2 com.amazon.ion.impl._Private_IonWriter (com.amazon.ion.impl._Private_IonWriter)2