EEExportGridPointHandler implements GridPointHandler { static Date getL2MjdTimeStamp(CompoundData compoundData) throws IOException { int index = compoundData.getType().getMemberIndex("Mean_Acq_Time"); if (index > 0) { return getOSUDPDate(compoundData, index); } final CompoundType type = compoundData.getType(); index = type.getMemberIndex("Days"); if (index >= 0) { return getSMUPDDate(compoundData); } return null; } EEExportGridPointHandler(DataContext targetContext);   EEExportGridPointHandler(DataContext targetContext, GridPointFilter targetFilter); @Override void handleGridPoint(int id, CompoundData gridPointData);  }
@Test public void testGetL2TimeStamp() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); MemoryCacheImageOutputStream ios = new MemoryCacheImageOutputStream(baos); ios.setByteOrder(ByteOrder.LITTLE_ENDIAN); ios.writeInt(1250); ios.writeInt(890); ios.writeInt(100); ios.close(); CompoundType type = COMPOUND("dontcare", MEMBER("Days", SimpleType.INT), MEMBER("Seconds", SimpleType.UINT), MEMBER("Microseconds", SimpleType.UINT)); byte[] byteData = baos.toByteArray(); DataContext context = new DataFormat(type, ByteOrder.LITTLE_ENDIAN).createContext( new ByteArrayIOHandler(byteData)); CompoundData compoundData = InstanceFactory.createCompound(context, null, type, 0, ByteOrder.LITTLE_ENDIAN); Date l2MjdTimeStamp = EEExportGridPointHandler.getL2MjdTimeStamp(compoundData); assertEquals(new Date(1054685690000L), l2MjdTimeStamp); baos = new ByteArrayOutputStream(); ios = new MemoryCacheImageOutputStream(baos); ios.setByteOrder(ByteOrder.LITTLE_ENDIAN); ios.writeInt(1252); ios.writeInt(890); ios.writeInt(100); ios.close(); byteData = baos.toByteArray(); context = new DataFormat(type, ByteOrder.LITTLE_ENDIAN).createContext( new ByteArrayIOHandler(byteData)); compoundData = InstanceFactory.createCompound(context, null, type, 0, ByteOrder.LITTLE_ENDIAN); l2MjdTimeStamp = EEExportGridPointHandler.getL2MjdTimeStamp(compoundData); assertEquals(new Date(1054858490000L), l2MjdTimeStamp); }
@Test public void testGetL2TimeStamp_notExistingMember() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); MemoryCacheImageOutputStream ios = new MemoryCacheImageOutputStream(baos); ios.setByteOrder(ByteOrder.LITTLE_ENDIAN); ios.writeFloat(26.99f); ios.close(); CompoundType type = COMPOUND("dontcare", MEMBER("schnickschnack", SimpleType.FLOAT)); byte[] byteData = baos.toByteArray(); DataContext context = new DataFormat(type, ByteOrder.LITTLE_ENDIAN).createContext( new ByteArrayIOHandler(byteData)); CompoundData compoundData = InstanceFactory.createCompound(context, null, type, 0, ByteOrder.LITTLE_ENDIAN); final Date l2MjdTimeStamp = EEExportGridPointHandler.getL2MjdTimeStamp(compoundData); assertNull(l2MjdTimeStamp); }
@Test public void testGetL2TimeStamp_zeroValues() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); MemoryCacheImageOutputStream ios = new MemoryCacheImageOutputStream(baos); ios.setByteOrder(ByteOrder.LITTLE_ENDIAN); ios.writeInt(0); ios.writeInt(0); ios.writeInt(0); ios.close(); CompoundType type = COMPOUND("dontcare", MEMBER("Mean_Acq_Time", COMPOUND("UTC_Type", MEMBER("Days", SimpleType.INT), MEMBER("Seconds", SimpleType.UINT), MEMBER("Microseconds", SimpleType.UINT)))); byte[] byteData = baos.toByteArray(); DataContext context = new DataFormat(type, ByteOrder.LITTLE_ENDIAN).createContext( new ByteArrayIOHandler(byteData)); CompoundData compoundData = InstanceFactory.createCompound(context, null, type, 0, ByteOrder.LITTLE_ENDIAN); Date l2MjdTimeStamp = EEExportGridPointHandler.getL2MjdTimeStamp(compoundData); assertNull(l2MjdTimeStamp); }