I have a Springboot application exposing a simple REST api, with several layers and autowired #Components, and I send a HTTP POST request to its #RestController through Postman, and in one of the subsequent components I'm doing stuff with the received data.
The problem is that when I send more requests in postman after the first has returned, the components seem to still contain information from the previous request that has already returned a response... How to avoid this? I want every request to be a "clean slate". It's almost as if it's not cleaning up when its done.. It's so annoying because I dont even know how to formulate the problem but I hope you understand.
In the following code the "actual_imported_rows" keeps increasing for subsequent requests:
#Data
#NoArgsConstructor
#Component
#Slf4j
public class StrekningImporter {
int expected_num_rows;
int actual_imported_rows;
HashMap<Long, StrekningEntity> successfulStrekning = new HashMap<>();
ArrayList<FailedImportEntry> unsuccessfulStrekning = new ArrayList<>();
public HashMap<Long, StrekningEntity> startImport(Sheet sheet, HashMap<Long, RegulativEntity> regulativHashMap,
HashMap<Long, SambandEntity> sambandHashMap) throws FailedImport {
expected_num_rows = sheet.getLastRowNum();
Iterator<Row> rows = sheet.iterator();
System.out.println("ACTUAL IMPORT SIZE: " + actual_imported_rows);
int rowNum = 0;
while (rows.hasNext()) {
// Skip header
if (rowNum == 0) {
rowNum++;
rows.next();
}
Row currentRow = rows.next();
try {
StrekningEntity strekning = iterateRow(currentRow, regulativHashMap, sambandHashMap);
successfulStrekning.put((long) strekning.getId(), strekning);
actual_imported_rows += 1;
} catch (FailedImportEntry failedImportEntry) {
unsuccessfulStrekning.add(failedImportEntry);
rowNum++;
continue;
}
rowNum++;
}
log.info("Imported Strekning : " + actual_imported_rows + " out of: " + expected_num_rows);
if (unsuccessfulStrekning.size() > 0) {
throw new FailedImport("Strekning", unsuccessfulStrekning);
}
return successfulStrekning;
}
private StrekningEntity iterateRow(Row currentRow, HashMap<Long, RegulativEntity> regulativHashMap,
HashMap<Long, SambandEntity> sambandHashMap) throws FailedImportEntry {
int strekning_id = 0;
String rutekode = "";
String vegkode = "";
int samband_id = 0;
String oppdragsgiver = "";
String fergeleie_fra = "";
String fergeleie_til = "";
double distanse = 0;
int reisetid = 0;
int regulativ_id = 0;
int sone = 0;
int sonepaslag = 0;
String vegnummer = "";
String merknad = "";
LocalDate gyldig_fra = null;
LocalDate gyldig_til = null;
StrekningEntity strekningEntity = null;
int colIndex = 0;
try {
int lastCellNum = currentRow.getLastCellNum();
for (; colIndex < lastCellNum; colIndex++) {
Cell currentCell = currentRow.getCell(colIndex);
switch (colIndex) {
case 0:
if (currentCell != null) {
strekning_id = (int) currentCell.getNumericCellValue();
}
break;
case 1:
if (currentCell != null) {
rutekode = currentCell.getStringCellValue();
}
break;
case 2:
if (currentCell != null) {
vegkode = currentCell.getStringCellValue();
}
break;
case 3:
if (currentCell != null) {
samband_id = (int) currentCell.getNumericCellValue();
}
break;
case 5:
if (currentCell != null) {
fergeleie_fra = currentCell.getStringCellValue();
}
break;
case 6:
if (currentCell != null) {
fergeleie_til = currentCell.getStringCellValue();
}
break;
case 8:
if (currentCell != null) {
break;
}
case 9:
if (currentCell != null) {
distanse = currentCell.getNumericCellValue();
}
break;
case 10:
if (currentCell != null) {
reisetid = (int) currentCell.getNumericCellValue();
}
break;
case 11:
if (currentCell != null) {
regulativ_id = (int) currentCell.getNumericCellValue();
}
break;
case 13:
if (currentCell != null) {
sone = (int) currentCell.getNumericCellValue();
}
break;
case 14:
if (currentCell != null) {
sonepaslag = (int) currentCell.getNumericCellValue();
}
break;
case 16:
if (currentCell != null) {
vegnummer = currentCell.getStringCellValue();
}
break;
case 17:
if (currentCell != null) {
merknad = currentCell.getStringCellValue();
}
break;
case 18:
if (currentCell != null) {
gyldig_fra = currentCell.getLocalDateTimeCellValue().toLocalDate();
}
break;
case 19:
if (currentCell != null) {
gyldig_til = currentCell.getLocalDateTimeCellValue().toLocalDate();
}
break;
default:
break;
}
}
SambandEntity samband = sambandHashMap.get((long) samband_id);
RegulativEntity regulativ = regulativHashMap.get((long) regulativ_id);
strekningEntity = new StrekningEntity((short) strekning_id, samband, fergeleie_fra, fergeleie_til,
(int) distanse, reisetid, regulativ, null, (short) sone, (short) sonepaslag, false, merknad, gyldig_fra,
gyldig_til, null);
} catch (Exception e) {
FailedImportEntry failedImportEntry = new FailedImportEntry(currentRow.getRowNum(), colIndex,
"class: " + e.getClass() + " | message: " + e.getMessage());
throw failedImportEntry;
}
return strekningEntity;
}
}
Any help or hints where the problem lies would be greatly appreciated :)
Related
I am trying to pass this method through my main() function but The loadMap already has the bufferreader so I am trying to use that rather than creating my own new buffer reader. How can I do this?
public static void main(String args[]) {
//throw exceptions here if args is empty
filename = args[0];
System.out.println(MapIO.loadMap(filename)[0]);
System.out.println(MapIO.loadMap(filename)[1]);
if (args.length < 1) {
System.err.println("Usage:\n" +"java CrawlGui mapname");
System.exit(1);
}
List<String> names=new LinkedList<String>();
try (BufferedReader reader = new BufferedReader(new FileReader(new
File(filename)))) {
String line;
while ((line = reader.readLine()) != null)
names.add(line);
System.out.println(names);
} catch (IOException e) {
e.printStackTrace();
}
MapIO.loadMap(filename);
launch(args);
}
/** Read information from a file created with saveMap
* #param filename Filename to read from
* #return null if unsucessful. If successful, an array of two Objects.
[0] being the Player object (if found) and
[1] being the start room.
* #detail. Do not add the player to the room they appear in, the caller
will be responsible for placing the player in the start room.
*/
public static Object[] loadMap(String filename) {
Player player = null;
try {
BufferedReader bf = new BufferedReader(
new FileReader(filename));
String line = bf.readLine();
int idcap = Integer.parseInt(line);
Room[] rooms = new Room[idcap];
for (int i = 0; i < idcap; ++i) {
line = bf.readLine();
if (line == null) {
return null;
}
rooms[i] = new Room(line);
}
for (int i = 0; i < idcap; ++i) { // for each room set up exits
line = bf.readLine();
int exitcount=Integer.parseInt(line);
for (int j=0; j < exitcount; ++j) {
line = bf.readLine();
if (line == null) {
return null;
}
int pos = line.indexOf(' ');
if (pos < 0) {
return null;
}
int target = Integer.parseInt(line.substring(0,pos));
String exname = line.substring(pos+1);
try {
rooms[i].addExit(exname, rooms[target]);
} catch (ExitExistsException e) {
return null;
} catch (NullRoomException e) {
return null;
}
}
}
for (int i = 0;i<idcap;++i) {
line = bf.readLine();
int itemcount = Integer.parseInt(line);
for (int j = 0; j < itemcount; ++j) {
line = bf.readLine();
if (line == null) {
return null;
}
Thing t = decodeThing(line, rooms[0]);
if (t == null) {
return null;
}
if (t instanceof Player) { // we don't add
player = (Player)t; // players to rooms
} else {
rooms[i].enter(t);
}
}
}
Object[] res = new Object[2];
res[0] = player;
res[1] = rooms[0];
return res;
} catch (IOException ex) {
return null;
} catch (IndexOutOfBoundsException ex) {
return null;
} catch (NumberFormatException nfe) {
return null;
}
}
You shouldn't do anything in main() other than call launch(). Move all the other startup code to your start() method. You can get the content of the args array using getParameters().getRaw():
#Override
public void start(Stage primaryStage) {
//throw exceptions here if args is empty
filename = getParameters().getRaw().get(0);
System.out.println(MapIO.loadMap(filename)[0]);
System.out.println(MapIO.loadMap(filename)[1]);
if (args.length < 1) {
System.err.println("Usage:\n" +"java CrawlGui mapname");
System.exit(1);
}
List<String> names=new LinkedList<String>();
try (BufferedReader reader = new BufferedReader(new FileReader(new
File(filename)))) {
String line;
while ((line = reader.readLine()) != null)
names.add(line);
System.out.println(names);
} catch (IOException e) {
e.printStackTrace();
}
Object[] whateverThisThingIs = MapIO.loadMap(filename);
// Now you have access to everything you need, at the point where you need it.
// existing start() code goes here...
}
public static void main(String args[]) {
launch(args);
}
As the title said,I was trapped to How to transfer FFmpeg's AVPacket to CUVID's CUVIDSOURCEDATAPACKET,and my main code about this question is below:`
AVPacket* avpkt;
avpkt = (AVPacket*)av_malloc(sizeof(AVPacket));
CUVIDSOURCEDATAPACKET cupkt;
int iPkt = 0;
while (av_read_frame(pFormatCtx, avpkt) >= 0) {
if (avpkt->stream_index == videoindex) {
cuCtxPushCurrent(g_oContext);
if (avpkt && avpkt->size) {
cupkt.payload_size = (unsigned long)avpkt->size;
cupkt.payload = (const unsigned char*)avpkt->data;
if (avpkt->pts != AV_NOPTS_VALUE) {
cupkt.flags = CUVID_PKT_TIMESTAMP;
if (pCodecCtx->pkt_timebase.num && pCodecCtx->pkt_timebase.den) {
AVRational tb;
tb.num = 1;
tb.den = AV_TIME_BASE;
cupkt.timestamp = av_rescale_q(avpkt->pts, pCodecCtx->pkt_timebase, tb);
}
else
cupkt.timestamp = avpkt->pts;
}
}
else {
cupkt.flags = CUVID_PKT_ENDOFSTREAM;
}
oResult = cuvidParseVideoData(hParser_, &cupkt);
if ((cupkt.flags & CUVID_PKT_ENDOFSTREAM) || (oResult != CUDA_SUCCESS)) {
break;
}
iPkt++;
printf("Succeed to read avpkt %d !\n", iPkt);
checkCudaErrors(cuCtxPopCurrent(NULL));
}
av_free_packet(avpkt);
}
and as you see,the code
cupkt.payload_size = (unsigned long)avpkt->size;
cupkt.payload = (const unsigned char*)avpkt->data;
needs to be corrected。
I'm poor at english,I hope I have expressed my self clearly。
I'm very happy today.Last night after I asked this question,I went to look through the source code of FFmpeg,after a few hours of hardwork ,I found a little difference between my code ande FFmpeg's.So I will anwser this question myself.
AVBitStreamFilterContext* h264bsfc = NULL;
if (pCodecCtx->codec_id == AV_CODEC_ID_H264 || pCodecCtx->codec_id == AV_CODEC_ID_HEVC) {
if (pCodecCtx->codec_id == AV_CODEC_ID_H264)
h264bsfc = av_bitstream_filter_init("h264_mp4toannexb");
else
h264bsfc = av_bitstream_filter_init("hevc_mp4toannexb");
}
AVPacket *avpkt;
avpkt = (AVPacket *)av_malloc(sizeof(AVPacket));
CUVIDSOURCEDATAPACKET cupkt;
int iPkt = 0;
while (av_read_frame(pFormatCtx, avpkt) >= 0){
if (avpkt->stream_index == videoindex){
cuCtxPushCurrent(g_oContext);
if (avpkt && avpkt->size) {
if (h264bsfc)
{
av_bitstream_filter_filter(h264bsfc, pFormatCtx->streams[videoindex]->codec, NULL, &avpkt->data, &avpkt->size, avpkt->data, avpkt->size, 0);
}
cupkt.payload_size = (unsigned long)avpkt->size;
cupkt.payload = (const unsigned char*)avpkt->data;
if (avpkt->pts != AV_NOPTS_VALUE) {
cupkt.flags = CUVID_PKT_TIMESTAMP;
if (pCodecCtx->pkt_timebase.num && pCodecCtx->pkt_timebase.den){
AVRational tb;
tb.num = 1;
tb.den = AV_TIME_BASE;
cupkt.timestamp = av_rescale_q(avpkt->pts, pCodecCtx->pkt_timebase, tb);
}
else
cupkt.timestamp = avpkt->pts;
}
}
else {
cupkt.flags = CUVID_PKT_ENDOFSTREAM;
}
oResult = cuvidParseVideoData(hParser_, &cupkt);
if ((cupkt.flags & CUVID_PKT_ENDOFSTREAM) || (oResult != CUDA_SUCCESS)){
break;
}
iPkt++;
//printf("Succeed to read avpkt %d !\n", iPkt);
checkCudaErrors(cuCtxPopCurrent(NULL));
}
av_free_packet(avpkt);
}
if (h264bsfc)
{
av_bitstream_filter_close(h264bsfc);
}
the main difference is below:
AVBitStreamFilterContext* h264bsfc = NULL;
if (pCodecCtx->codec_id == AV_CODEC_ID_H264 || pCodecCtx->codec_id == AV_CODEC_ID_HEVC) {
if (pCodecCtx->codec_id == AV_CODEC_ID_H264)
h264bsfc = av_bitstream_filter_init("h264_mp4toannexb");
else
h264bsfc = av_bitstream_filter_init("hevc_mp4toannexb");
}
········
if (h264bsfc)
{
av_bitstream_filter_filter(h264bsfc, pFormatCtx->streams[videoindex]->codec, NULL, &avpkt->data, &avpkt->size, avpkt->data, avpkt->size, 0);
}
·········
if (h264bsfc)
{
av_bitstream_filter_close(h264bsfc);
}
this is because the file I use is H264 format,there is something must be done with NALU of H264(I don't know what is it,I got it from anwsers of another people's question,and I haven't know it clearly,maybe the problem is not like what I said).The code I add works for me,and I hope my anwser coulde help you.As I memtioned,I'm poor at English,if you are confused about what I said,just go to the code.
need information about the buttons of the device, how many, etc.
I tried iokit but got a strange list
name = IOUSBRootHubDevice
name = IOUSBHubDevice
name = IOUSBDevice
name = IOUSBHubDevice
name = IOUSBDevice
name = IOUSBRootHubDevice
name = IOUSBHubDevice
name = IOUSBDevice
name = IOUSBDevice
name = IOUSBDevice
my code
CFMutableDictionaryRef matchingDict;
io_iterator_t iter;
kern_return_t kr;
io_service_t device;
io_name_t name;
//io_object_t device;
/* set up a matching dictionary for the class */
matchingDict = IOServiceMatching(kIOUSBDeviceClassName);
if (matchingDict == NULL){
return -1; // fail
}
/* Now we have a dictionary, get an iterator.*/
kr = IOServiceGetMatchingServices(kIOMasterPortDefault, matchingDict, &iter);
if (kr != KERN_SUCCESS){
return -1;
}
/* iterate */
while ((device = IOIteratorNext(iter))){
IOObjectGetClass(device, name);
printf("name = %s \n", name);
/* do something with device, eg. check properties */
/* ... */
/* And free the reference taken before continuing to the next item */
IOObjectRelease(device);
}
/* Done, release the iterator */
IOObjectRelease(iter);
there are probably a better option, but I can not find in google
turned himself in, as it so
static void MyCreateHIDDeviceInterface(io_object_t hidDevice,
IOHIDDeviceInterface122 ***hidDeviceInterface)
{
io_name_t className;
IOCFPlugInInterface **plugInInterface = NULL;
HRESULT plugInResult = S_OK;
SInt32 score = 0;
IOReturn ioReturnValue = kIOReturnSuccess;
ioReturnValue = IOObjectGetClass(hidDevice, className);
printf("Failed to get class name.\n");//print_errmsg_if_io_err(ioReturnValue, "Failed to get class name.");
printf("Found device type %s\n", className);
ioReturnValue = IOCreatePlugInInterfaceForService(hidDevice,
kIOHIDDeviceUserClientTypeID,
kIOCFPlugInInterfaceID,
&plugInInterface,
&score);
if (ioReturnValue == kIOReturnSuccess)
{
//Call a method of the intermediate plug-in to create the device
//interface
plugInResult = (*plugInInterface)->QueryInterface(plugInInterface,
CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID),
(LPVOID *) hidDeviceInterface);
printf("Couldn't create HID class device interface.\n");//print_errmsg_if_err(plugInResult != S_OK, "Couldn't create HID class device interface");
IODestroyPlugInInterface(plugInInterface);
//(*plugInInterface)->Release(plugInInterface);
}
}
void getCookies(IOHIDDeviceInterface122** deviceInterface){
CFArrayRef elements;
CFDictionaryRef element;
CFTypeRef object;
long number;
long usagePage;
long usage;
IOHIDElementCookie cookie;
(*deviceInterface)->copyMatchingElements(deviceInterface, NULL, &elements);
for ( CFIndex i=0; i<CFArrayGetCount(elements); i++ ){
element = (CFDictionaryRef)CFArrayGetValueAtIndex(elements, i);
// Get usage page
object = CFDictionaryGetValue(element, CFSTR(kIOHIDElementUsagePageKey));
if( object==0 || CFGetTypeID(object) != CFNumberGetTypeID() ){
continue;
}
if( !CFNumberGetValue((CFNumberRef) object, kCFNumberLongType, &number) ){
continue;
}
usagePage = number;
if( usagePage!=kHIDPage_GenericDesktop && usagePage!=kHIDPage_Button ){
continue;
}
// Get usage
object = CFDictionaryGetValue( element, CFSTR(kIOHIDElementUsageKey) );
if( object==0 || CFGetTypeID(object) != CFNumberGetTypeID() ){
continue;
}
if( !CFNumberGetValue((CFNumberRef) object, kCFNumberLongType, &number) ){
continue;
}
usage = number;
// Get cookie
object = CFDictionaryGetValue( element, CFSTR(kIOHIDElementCookieKey) );
if( object==0 || CFGetTypeID(object) != CFNumberGetTypeID() ){
continue;
}
if( !CFNumberGetValue((CFNumberRef) object, kCFNumberLongType, &number) ){
continue;
}
cookie = (IOHIDElementCookie) number;
if(usagePage == kHIDPage_GenericDesktop){
switch( usage )
{
case kHIDUsage_GD_Pointer: {
printf("kHIDUsage_GD_Pointer \n");
break;
}
case kHIDUsage_GD_Mouse: {
printf("kHIDUsage_GD_Mouse \n");
break;
};
case kHIDUsage_GD_Joystick: {
printf("kHIDUsage_GD_Joystick \n");
break;
}
case kHIDUsage_GD_GamePad: {
printf("kHIDUsage_GD_GamePad \n");
break;
}
case kHIDUsage_GD_Keyboard:{
printf("kHIDUsage_GD_Keyboard \n");
break;
};
case kHIDUsage_GD_Keypad: {
printf("kHIDUsage_GD_Keypad \n");
break;
};
case kHIDUsage_GD_MultiAxisController:{
printf("kHIDUsage_GD_MultiAxisController \n");
break;
};
case kHIDUsage_GD_X: {
printf("kHIDUsage_GD_X \n");
break;
};
case kHIDUsage_GD_Y: {
printf("kHIDUsage_GD_Y \n");
break;
};
}
} else if( usagePage == kHIDPage_Button){
printf("kHIDPage_Button \n");
}
}
}
int main(int argc, const char * argv[])
{
CFMutableDictionaryRef matchingDict;
io_iterator_t iter;
kern_return_t kr;
io_object_t device;
char name[128];
IOHIDDeviceInterface122 **deviceInterface = NULL;
/* set up a matching dictionary for the class */
matchingDict = IOServiceMatching(kIOHIDDeviceKey);//kIOHIDDeviceKey
if (matchingDict == NULL)
{
return -1; // fail
}
/* Now we have a dictionary, get an iterator.*/
kr = IOServiceGetMatchingServices(kIOMasterPortDefault, matchingDict, &iter);
if (kr != KERN_SUCCESS)
{
return -1;
}
/* iterate */
while ((device = IOIteratorNext(iter)))
{
IOObjectGetClass(device, name);
if(!strcmp(name,"BNBMouseDevice")){
MyCreateHIDDeviceInterface(device, &deviceInterface);
if(*deviceInterface != NULL){
getCookies(deviceInterface);
(*deviceInterface)->Release(deviceInterface);
}
printf("name = %s \n \n", name);
}else if(!strcmp(name,"AppleBluetoothHIDKeyboard")){
MyCreateHIDDeviceInterface(device, &deviceInterface);
if(*deviceInterface != NULL){
getCookies(deviceInterface);
(*deviceInterface)->Release(deviceInterface);
}
printf("name = %s \n \n", name);
}else if(!strcmp(name,"IOUSBHIDDriver")){
MyCreateHIDDeviceInterface(device, &deviceInterface);
if(*deviceInterface != NULL){
getCookies(deviceInterface);
(*deviceInterface)->Release(deviceInterface);
}
printf("name = %s \n \n", name);
}
IOObjectRelease(device);
}
/* Done, release the iterator */
IOObjectRelease(iter);
return 0;
}
I want to hide files (in my program). I decided to use NtQueryDirectoryFile. But the files are not hidden, the code does not work. I don't use a driver, I use user mode. Can anybody help me please?
The code snippet:
typedef NTSTATUS (WINAPI * NTQUERYDIRECTORYFILE) (IN HANDLE FileHandle,IN HANDLE Event OPTIONAL,IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,IN PVOID ApcContext OPTIONAL,OUT PIO_STATUS_BLOCK IoStatusBlock,OUT PVOID FileInformation,IN ULONG FileInformationLength,IN MYFILE_INFORMATION_CLASS FileInformationClass,IN BOOLEAN ReturnSingleEntry,IN PUNICODE_STRING FileName OPTIONAL,IN BOOLEAN RestartScan);
NTQUERYDIRECTORYFILE OriginalNtQueryDirectoryFile;
#define STATUS_NO_SUCH_FILE 0xC000000F
NTSTATUS
HookedNtQueryDirectoryFile(
IN HANDLE FileHandle,
IN HANDLE Event OPTIONAL,
IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
IN PVOID ApcContext OPTIONAL,
OUT PIO_STATUS_BLOCK IoStatusBlock,
OUT PVOID FileInformation,
IN ULONG FileInformationLength,
IN MYFILE_INFORMATION_CLASS FileInformationClass,
IN BOOLEAN ReturnSingleEntry,
IN PUNICODE_STRING FileName OPTIONAL,
IN BOOLEAN RestartScan)
{
NTSTATUS status = OriginalNtQueryDirectoryFile(FileHandle,Event,ApcRoutine,ApcContext,IoStatusBlock,FileInformation,FileInformationLength,FileInformationClass,ReturnSingleEntry,FileName,RestartScan);
vector<wstring> listDataForHidding;
listDataForHidding.push_back(L"afile.txt");
listDataForHidding.push_back(L"bfile.txt");
listDataForHidding.push_back(L"cfile.txt");
listDataForHidding.push_back(L"dfile.txt");
if (NT_SUCCESS(status))
{
PMYFILE_DIRECTORY_INFORMATION FileDirectoryInfo, LastFileDirectoryInfo;
PMYFILE_FULL_DIR_INFORMATION LastFileFullDirectoryInfo, FileFullDirectoryInfo;
PMYFILE_BOTH_DIR_INFORMATION LastFileBothDirectoryInfo, FileBothDirectoryInfo;
PMYFILE_NAMES_INFORMATION LastFileNamesInfo, FileNamesInfo;
ULONG Offset = 0;
BOOL bNeedHide = FALSE;
switch (FileInformationClass)
{
case FileDirectoryInformation :
FileDirectoryInfo = NULL;
do
{
//FileDirectoryInfo = (PVOID)((ULONG)FileInformation + Offset);
FileDirectoryInfo = (PMYFILE_DIRECTORY_INFORMATION)((ULONG)FileInformation + Offset);
LastFileDirectoryInfo = FileDirectoryInfo;
wstring wstrCurrFileName = FileDirectoryInfo->FileName;
bNeedHide = FALSE;
for(size_t index = 0; index < listDataForHidding.size(); index ++)
{
if(wstrCurrFileName.find(listDataForHidding[index]) != wstring::npos)
{
bNeedHide = TRUE;
break;
}
}
//if (FileDirectoryInfo->FileName[0] == 0x5F00)
if(bNeedHide == TRUE)
{
if (!FileDirectoryInfo->NextEntryOffset)
{
if (LastFileDirectoryInfo) LastFileDirectoryInfo->NextEntryOffset = 0;
else status = STATUS_NO_SUCH_FILE;
return status;
} else
if (LastFileDirectoryInfo) LastFileDirectoryInfo->NextEntryOffset += FileDirectoryInfo->NextEntryOffset;
}
Offset += FileDirectoryInfo->NextEntryOffset;
} while (FileDirectoryInfo->NextEntryOffset);
break;
case FileFullDirectoryInformation :
FileFullDirectoryInfo = NULL;
do
{
LastFileFullDirectoryInfo = FileFullDirectoryInfo;
//FileFullDirectoryInfo = (PVOID)((ULONG)FileInformation + Offset);
FileFullDirectoryInfo = (PMYFILE_FULL_DIR_INFORMATION)((ULONG)FileInformation + Offset);
wstring wstrCurrFileName = FileDirectoryInfo->FileName;
bNeedHide = FALSE;
for(size_t index = 0; index < listDataForHidding.size(); index ++)
{
if(wstrCurrFileName.find(listDataForHidding[index]) != wstring::npos)
{
bNeedHide = TRUE;
break;
}
}
//if (FileFullDirectoryInfo->FileName[0] == 0x5F00)
if(bNeedHide == TRUE)
{
if (!FileFullDirectoryInfo->NextEntryOffset)
{
if (LastFileFullDirectoryInfo) LastFileFullDirectoryInfo->NextEntryOffset = 0;
else status = STATUS_NO_SUCH_FILE;
return status;
} else
if (LastFileFullDirectoryInfo) LastFileFullDirectoryInfo->NextEntryOffset += FileFullDirectoryInfo->NextEntryOffset;
}
Offset += FileFullDirectoryInfo->NextEntryOffset;
} while (FileFullDirectoryInfo->NextEntryOffset);
break;
case FileBothDirectoryInformation :
FileBothDirectoryInfo = NULL;
do
{
LastFileBothDirectoryInfo = FileBothDirectoryInfo;
//FileBothDirectoryInfo = (PVOID)((ULONG)FileInformation + Offset);
FileBothDirectoryInfo = (PMYFILE_BOTH_DIR_INFORMATION)((ULONG)FileInformation + Offset);
wstring wstrCurrFileName = FileDirectoryInfo->FileName;
bNeedHide = FALSE;
for(size_t index = 0; index < listDataForHidding.size(); index ++)
{
if(FileBothDirectoryInfo->FileNameLength > 1 && wstrCurrFileName.find(listDataForHidding[index]) != wstring::npos)
{
bNeedHide = TRUE;
break;
}
}
//if (FileBothDirectoryInfo->FileNameLength > 1 && FileBothDirectoryInfo->FileName[0] == 0x5F00)
if(bNeedHide == TRUE)
{
if (!FileBothDirectoryInfo->NextEntryOffset)
{
if (LastFileBothDirectoryInfo) LastFileBothDirectoryInfo->NextEntryOffset = 0;
else status = STATUS_NO_SUCH_FILE;
return status;
} else
if (LastFileBothDirectoryInfo) LastFileBothDirectoryInfo->NextEntryOffset += FileBothDirectoryInfo->NextEntryOffset;
}
Offset += FileBothDirectoryInfo->NextEntryOffset;
} while (FileBothDirectoryInfo->NextEntryOffset);
break;
case FileNamesInformation :
FileNamesInfo = NULL;
do
{
LastFileNamesInfo = FileNamesInfo;
//FileNamesInfo = (PVOID)((ULONG)FileInformation + Offset);
FileNamesInfo = (PMYFILE_NAMES_INFORMATION)((ULONG)FileInformation + Offset);
wstring wstrCurrFileName = FileDirectoryInfo->FileName;
bNeedHide = FALSE;
for(size_t index = 0; index < listDataForHidding.size(); index ++)
{
if(wstrCurrFileName.find(listDataForHidding[index]) != wstring::npos)
{
bNeedHide = TRUE;
break;
}
}
//if (FileNamesInfo->FileName[0] == 0x5F00)
if(bNeedHide == TRUE)
{
if (!FileNamesInfo->NextEntryOffset)
{
if(LastFileNamesInfo) LastFileNamesInfo->NextEntryOffset = 0;
else status = STATUS_NO_SUCH_FILE;
return status;
} else
if (LastFileNamesInfo) LastFileNamesInfo->NextEntryOffset += FileNamesInfo->NextEntryOffset;
}
Offset += FileNamesInfo->NextEntryOffset;
} while (FileNamesInfo->NextEntryOffset);
break;
}
}
return status;
}
I want to display a listfield with live image in all rows of the listfield
check out this
also use the following code for displaying live images:
public static String getImageFromUrl(String url) {
//Image img = null;
String imageData = null;
try
{
imageData = getDataFromUrl(url);
//img = Image.createImage(imageData.getBytes(), 0,imageData.length() );
}
catch(Exception e1) {
e1.printStackTrace();
}
return imageData;
}
public static String getDataFromUrl(String url)
throws IOException {
StringBuffer b = new StringBuffer();
InputStream is = null;
HttpConnection c = null;
long len = 0 ;
int ch = 0;
ConnectionFactory connFact = new ConnectionFactory();
ConnectionDescriptor connDesc;
connDesc = connFact.getConnection(url);
if (connDesc != null)
{
//HttpConnection httpConn;
c = (HttpConnection)connDesc.getConnection();
}
// c = (HttpConnection)Connector.open(url);
is = c.openInputStream();
len = c.getLength();
if( len != -1) {
// Read exactly Content-Length bytes
for(int i =0 ; i < len ; i++ )
if((ch = is.read()) != -1) {
b.append((char) ch);
}
} else {
//Read until the connection is closed.
while ((ch = is.read()) != -1) {
len = is.available() ;
b.append((char)ch);
}
}
is.close();
c.close();
return b.toString();
}
Hope this will help you.