use of com.amazon.ion.Timestamp in project ion-java by amzn.
the class IonReaderBinaryIncrementalTest method timestamps.
@Test
public void timestamps() throws Exception {
final List<Timestamp> timestamps = new ArrayList<Timestamp>();
timestamps.add(Timestamp.valueOf("2000T"));
timestamps.add(Timestamp.valueOf("2000-01T"));
timestamps.add(Timestamp.valueOf("2000-01-02T"));
timestamps.add(Timestamp.valueOf("2000-01-02T03:04Z"));
timestamps.add(Timestamp.valueOf("2000-01-02T03:04:05Z"));
timestamps.add(Timestamp.valueOf("2000-01-02T03:04:05.6Z"));
timestamps.add(Timestamp.valueOf("2000-01-02T03:04:05.06Z"));
timestamps.add(Timestamp.valueOf("2000-01-02T03:04:05.006Z"));
timestamps.add(Timestamp.valueOf("2000-01-02T03:04:05.600Z"));
timestamps.add(Timestamp.valueOf("2000-01-02T03:04:05.060Z"));
timestamps.add(Timestamp.valueOf("2000-01-02T03:04:05.060-07:00"));
timestamps.add(Timestamp.valueOf("2000-01-02T03:04:05.060+07:00"));
timestamps.add(Timestamp.valueOf("2000-01-02T03:04:05+07:00"));
timestamps.add(Timestamp.valueOf("2000-01-02T03:04+07:00"));
timestamps.add(Timestamp.valueOf("2000-01-02T03:04:05.9999999Z"));
IonReaderBinaryIncremental reader = readerFor(new WriterFunction() {
@Override
public void write(IonWriter writer) throws IOException {
for (Timestamp timestamp : timestamps) {
writer.writeTimestamp(timestamp);
}
}
});
for (Timestamp timestamp : timestamps) {
assertEquals(IonType.TIMESTAMP, reader.next());
assertEquals(timestamp, reader.timestampValue());
}
assertNull(reader.next());
assertNull(reader.getType());
reader.close();
}
use of com.amazon.ion.Timestamp in project ion-java by amzn.
the class IonReaderBinaryRawLargeStreamTest method cleanlyFailsOnLargeContainerIncremental.
@Test
public void cleanlyFailsOnLargeContainerIncremental() throws Exception {
final Timestamp timestamp = Timestamp.forDay(2000, 1, 1);
byte[] data = testData(timestamp);
// 42 makes the value exceed Integer.MAX_VALUE by an arbitrary amount.
final int totalNumberOfBatches = (Integer.MAX_VALUE / data.length) + 42;
ByteArrayOutputStream header = new ByteArrayOutputStream();
header.write(BINARY_VERSION_MARKER_1_0);
// S-exp with length subfield.
header.write(0xCE);
// Length
IonBinary.writeVarUInt(header, (long) data.length * totalNumberOfBatches);
InputStream inputStream = new SequenceInputStream(new ByteArrayInputStream(header.toByteArray()), // This will provide the data 'totalNumberOfBatches' times
new RepeatInputStream(data, totalNumberOfBatches - 1));
IonReader reader = IonReaderBuilder.standard().withIncrementalReadingEnabled(true).build(inputStream);
thrown.expect(IonException.class);
reader.next();
}
use of com.amazon.ion.Timestamp in project ion-java by amzn.
the class ReverseBinaryEncoder method writeIonTimestampContent.
private void writeIonTimestampContent(IonTimestamp val) {
if (val.isNullValue()) {
writeByte((byte) (TYPE_TIMESTAMP | NULL_LENGTH_MASK));
} else {
final int originalOffset = myBuffer.length - myOffset;
Timestamp t = val.timestampValue();
// Time and date portion
switch(t.getPrecision()) {
// Fall through each case - by design
case FRACTION:
case SECOND:
{
BigDecimal fraction = t.getZFractionalSecond();
if (fraction != null) {
assert (fraction.signum() >= 0 && !fraction.equals(BigDecimal.ZERO)) : "Bad timestamp fraction: " + fraction;
writeIonDecimalContent(fraction);
}
writeVarUInt(t.getZSecond());
}
case MINUTE:
writeVarUInt(t.getZMinute());
writeVarUInt(t.getZHour());
case DAY:
writeVarUInt(t.getZDay());
case MONTH:
writeVarUInt(t.getZMonth());
case YEAR:
writeVarUInt(t.getZYear());
break;
default:
throw new IllegalStateException("unrecognized Timestamp precision: " + t.getPrecision());
}
// Offset portion
Integer offset = t.getLocalOffset();
if (offset == null) {
// Negative 0 (no timezone)
writeByte((byte) (0x80 | 0x40));
} else {
writeVarInt(offset.intValue());
}
writePrefix(TYPE_TIMESTAMP, myBuffer.length - myOffset - originalOffset);
}
}
use of com.amazon.ion.Timestamp in project ion-java by amzn.
the class _Private_IonWriterBase method writeTimestampUTC.
public void writeTimestampUTC(Date value) throws IOException {
Timestamp time = Timestamp.forDateZ(value);
writeTimestamp(time);
}
use of com.amazon.ion.Timestamp in project ion-java by amzn.
the class IonReaderTextSystemX method getIonValue.
public IonValue getIonValue(IonSystem sys) {
if (isNullValue()) {
switch(_value_type) {
case NULL:
return sys.newNull();
case BOOL:
return sys.newNullBool();
case INT:
return sys.newNullInt();
case FLOAT:
return sys.newNullFloat();
case DECIMAL:
return sys.newNullDecimal();
case TIMESTAMP:
return sys.newNullTimestamp();
case SYMBOL:
return sys.newNullSymbol();
case STRING:
return sys.newNullString();
case CLOB:
return sys.newNullClob();
case BLOB:
return sys.newNullBlob();
case LIST:
return sys.newNullList();
case SEXP:
return sys.newNullSexp();
case STRUCT:
return sys.newNullString();
default:
throw new IonException("unrecognized type encountered");
}
}
switch(_value_type) {
case NULL:
return sys.newNull();
case BOOL:
return sys.newBool(booleanValue());
case INT:
return sys.newInt(longValue());
case FLOAT:
return sys.newFloat(doubleValue());
case DECIMAL:
return sys.newDecimal(decimalValue());
case TIMESTAMP:
IonTimestamp t = sys.newNullTimestamp();
Timestamp ti = timestampValue();
t.setValue(ti);
return t;
case SYMBOL:
return sys.newSymbol(stringValue());
case STRING:
return sys.newString(stringValue());
case CLOB:
IonClob clob = sys.newNullClob();
// FIXME inefficient: both newBytes and setBytes copy the data
clob.setBytes(newBytes());
return clob;
case BLOB:
IonBlob blob = sys.newNullBlob();
// FIXME inefficient: both newBytes and setBytes copy the data
blob.setBytes(newBytes());
return blob;
case LIST:
IonList list = sys.newNullList();
fillContainerList(sys, list);
return list;
case SEXP:
IonSexp sexp = sys.newNullSexp();
fillContainerList(sys, sexp);
return sexp;
case STRUCT:
IonStruct struct = sys.newNullStruct();
fillContainerStruct(sys, struct);
return struct;
default:
throw new IonException("unrecognized type encountered");
}
}
Aggregations