Odd IO situation

Have an IO class defined in the header file below:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
    class file_byte_stream : public byte_stream_interface {
      private:
#if defined(_MSC_VER) || defined(_WIN32)
        HANDLE file_stream;
#else      
        FILE* file_stream;
#endif
        // Opens the file and stores the file buffer handle in
        // file_stream.  If the open fails, an exception is thrown.
        // If the open succeeds, file_stream is set to the FILE*
        // associated with the file.
        void open(const char* filename) {
#if defined(_MSC_VER) || defined(_WIN32)
            file_stream = CreateFileA(filename,
                                      GENERIC_READ,
                                      FILE_SHARE_READ,
                                      NULL,
                                      OPEN_EXISTING,
                                      FILE_ATTRIBUTE_NORMAL,
                                      NULL);
            if (file_stream == INVALID_HANDLE_VALUE) {
                throw file_not_found
                    (message() << "In file_byte_stream, the file \"" << filename << "\" could not be opened",
                     filename);
            }
//fopen(filename, "rb");
#else
            file_stream = fopen(filename, "r");

            if (!file_stream) {
                throw file_not_found
                    (message() << "In file_byte_stream, the file \"" << filename << "\" could not be opened",
                     filename);
            }
#endif
        }

        // Closes the file associated with file_stream.  If
        // file_stream is 0, close() does nothing.
        void close() {
#if defined(_MSC_VER) || defined(_WIN32)
            if (file_stream != INVALID_HANDLE_VALUE) 
                CloseHandle(file_stream);
#else
            if (file_stream) 
                fclose(file_stream);
#endif
            file_stream = 0;
        }

      public:
        // Creates a byte stream given a file name.
        file_byte_stream(const char* filename) : file_stream(0) { open(filename); }

        // Creates a byte stream given a file name and memory allocator.
        file_byte_stream(memory_allocator_interface&, const char* filename) : file_stream(0) {
            open(filename);
        }

        // Resets the byte stream with a new file.
        void reset(const char* filename) {
            close();
            open(filename);
        }
        // Reads <em>n</em> bytes from the byte stream, and stores
        // them at <em>a</em>.
        virtual size_t read(void* a, size_t n) {
#if defined(_MSC_VER) || defined(_WIN32)
            DWORD bytes_read = 0;
            ReadFile(file_stream, static_cast<char*>(a), DWORD (n), &bytes_read, NULL);
            return bytes_read;
#else
            return fread(static_cast<char*>(a), sizeof(char), n, file_stream);
#endif
        }
        // The virtual desctructor.  Close the file stream owned by
        // this object.
        virtual ~file_byte_stream() {
            close();
        }
    };

Am attempting to call it in a JNI function below:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
JNIEXPORT jlong JNICALL Java_com_sra_pipeline_servers_summarizer_JSummarizer_getSummary
  (JNIEnv *env, jobject object, jlong sPtr, jstring filePath, jlong inPtr, 
		  jlong sentOutPtr, jlong phraseOutPtr) {
	jboolean isCopy;
	jlong summaryPtr;
	inxight::summarizer_interface* sumrzr = (inxight::summarizer_interface*)((long)sPtr);
	const char* cfile;
	cfile = env->GetStringUTFChars(filePath, &isCopy);
	printf("cfile %s \n", cfile);
	if(cfile == NULL) {
		printf("cfile is NULL");
		return 0;
	}
	//DebugBreak();
	file_byte_stream input_stream(cfile);	summarization_input_options* inOpts = 
		(summarization_input_options*)((long)inPtr);
	summarization_sentence_output* sentOpt = 
		(summarization_sentence_output*)((long)sentOutPtr);
	summarization_phrase_output* phraseOpt = 
		(summarization_phrase_output*)((long)phraseOutPtr);
	const char* query_string = NULL;
	int query_length = 0;
	const char* query_encoding = NULL;
	summarization summary (*sumrzr, input_stream, *inOpts, *sentOpt, 
			*phraseOpt, query_string, query_length, query_encoding);
	env->ReleaseStringUTFChars(filePath, cfile);
	summaryPtr = (jlong)((long)&summary);
	return(summaryPtr);
}

In the bolded section, am converting a Java String into a C++ constant char*.
The printf outputs the following:
cfile D:\Servers\SummarizerServer\input\aaawgqM4Ob.html
This is a valid path within an Eclipse project SummarizerServer.
The file containing the above function is compiled/linked into a dll which resides in the "native" directory off the project root.
Have tried all kinds of path designations absolute as above, and relative. My Java code can find and load the test file. For some reason I get an exception from the call to file_byte_stream. At first I thought it must be a path problem, and tried all the permutations with no joy. There must be another reason why an exception is generated.
Oddly enough the vendor has a test executable that built on the same API which allows designating a file on the commandline. Using it I was able to load the file from a variety of locations using the usual paths.
Any ideas or insights are welcome,
Jim
Topic archived. No new replies allowed.