Code example for Timestamp

Methods: setNanos, setTime

0
  private static final int HAS_DECIMAL_MASK = 0x80000000;
 
  private static final DateFormat dateFormat =
    new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
  private Timestamp timestamp = new Timestamp(0);
 
  /** 
   * true if data is stored in timestamp field rather than byte arrays. 
   *      allows for lazy conversion to bytes when necessary 
   * false otherwise 
   */ 
  private boolean bytesEmpty;
  private boolean timestampEmpty;
 
  /* Allow use of external byte[] for efficiency */ 
  private byte[] currentBytes;
  private final byte[] internalBytes = new byte[9];
  private byte[] externalBytes;
  private int offset;
 
  /* Reused to read VInts */ 
  static private final VInt vInt = new VInt();
 
  /* Constructors */ 
  public TimestampWritable() { 
    Arrays.fill(internalBytes, (byte) 0x0);
    bytesEmpty = false;
    currentBytes = internalBytes;
    offset = 0;
 
    clearTimestamp(); 
  } 
 
  public TimestampWritable(byte[] bytes, int offset) {
    set(bytes, offset);
  } 
 
  public TimestampWritable(TimestampWritable t) {
    this(t.getBytes(), 0);
  } 
 
  public TimestampWritable(Timestamp t) {
    set(t);
  } 
 
  public void set(byte[] bytes, int offset) {
    externalBytes = bytes;
    this.offset = offset;
    bytesEmpty = false;
    currentBytes = externalBytes;
 
    clearTimestamp(); 
  } 
 
  public void set(Timestamp t) {
    if (t == null) {
      timestamp.setTime(0);
      timestamp.setNanos(0);
      return; 
    } 
    this.timestamp = t;
    bytesEmpty = true;
    timestampEmpty = false;