JNIEXPORT jobject JNICALL Java_cgm_MetafileReader_read (JNIEnv *env, jobject self, jobject interface) { nitf_Error error; nitf_IOInterface* io; cgm_Metafile *metafile; cgm_MetafileReader *reader = _GetObj(env, self); /* get some classIDs */ jclass ioInterfaceClass = (*env)->GetObjectClass(env, interface); jclass metafileClass = (*env)->FindClass(env, "cgm/Metafile"); /* get the IOInterface */ jmethodID methodID = (*env)->GetMethodID(env, ioInterfaceClass, "getAddress", "()J"); io = (nitf_IOInterface*) ((*env)->CallLongMethod(env, interface, methodID)); /* just to be sure, seek to start of file */ if (nitf_IOInterface_seek(io, 0, NITF_SEEK_SET, &error) == -1) goto CATCH_ERROR; if (!(metafile = cgm_MetafileReader_read(reader, io, &error))) goto CATCH_ERROR; methodID = (*env)->GetMethodID(env, metafileClass, "<init>", "(J)V"); return (*env)->NewObject(env, metafileClass, methodID, (jlong) metafile); CATCH_ERROR: _ThrowNITFException(env, error.message); return NULL; }
NITFPRIV(NITF_BOOL) implStart(nitf_DecompressionControl* control, nitf_IOInterface* io, nitf_Uint64 offset, nitf_Uint64 fileLength, nitf_BlockingInfo* blockInfo, nitf_Uint64* blockMask, nitf_Error* error) { ImplControl *implControl = NULL; /* TODO: In order to support M8, I think we would update this */ (void)blockMask; implControl = (ImplControl*)control; if (nitf_IOInterface_seek(io, offset, NITF_SEEK_SET, error) < 0) goto CATCH_ERROR; if (!(implControl->reader = j2k_Reader_openIO(io, error))) goto CATCH_ERROR; implControl->offset = offset; implControl->fileLength = fileLength; implControl->blockInfo = *blockInfo; return NITF_SUCCESS; CATCH_ERROR: { implMemFree(implControl); return NITF_FAILURE; } }
/* * Private read implementation for file source. */ NITFPRIV(NITF_BOOL) IOSource_read(NITF_DATA * data, char *buf, nitf_Off size, nitf_Error * error) { IOSourceImpl *source = toIOSource(data, error); if (!source) return NITF_FAILURE; if (!NITF_IO_SUCCESS(nitf_IOInterface_seek(source->io, source->mark, NITF_SEEK_SET, error))) return NITF_FAILURE; if (source->pixelSkip == 0) return IOSource_contigRead(source, buf, size, error); return IOSource_offsetRead(source, buf, size, error); }
/* * Private read implementation for file source. */ NITFPRIV(NITF_BOOL) FileSource_read(NITF_DATA * data, char *buf, nitf_Off size, nitf_Error * error) { FileSourceImpl *fileSource = toFileSource(data, error); if (!fileSource) return NITF_FAILURE; if (!NITF_IO_SUCCESS(nitf_IOInterface_seek(fileSource->io, fileSource->mark, NITF_SEEK_SET, error))) return NITF_FAILURE; if (fileSource->byteSkip == 0) return FileSource_contigRead(fileSource, buf, size, error); return FileSource_offsetRead(fileSource, buf, size, error); }