Overwriting Native Methods

I want to make my own TempFileInputStream class that extends FileInputStream and overwrites close() so that it deletes the file as well. It's not working yet, and I wonder if the problem has something to do with that I'm trying to overwrite a native method (the subtleties of which I'm not clear on). Please share any insights.

[344 byte] By [rocketscienceguy] at [2007-9-26 3:09:24]
# 1
I don't see why it wouldn't work. You are not really overwriting anything.why don't you post some code snippets.
bschauwe at 2007-6-29 11:15:06 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2

Hi bschauwe, here are the code snippets.

Using the following class produces a FileNotFoundException in the init.

java.io.FileNotFoundException: /home/hopper/id0/www/organizer/tmp/foobar997121798292

at java.lang.Throwable.<init>(Compiled Code)

at java.lang.Exception.<init>(Compiled Code)

at java.io.IOException.<init>(Compiled Code)

at java.io.FileNotFoundException.<init>(Compiled Code)

at java.io.FileInputStream.<init>(Compiled Code)

at java.io.FileInputStream.<init>(Compiled Code)

at organizer.multipart.TempFileInputStream.<init>(Compiled Code)

Using FileInputStream in the same place and it works fine (without deleting the file on close of course).

--

import java.io.FileInputStream;

import java.io.IOException;

import java.io.File;

public class TempFileInputStream extends FileInputStream {

private File m_file;

TempFileInputStream(File file)

throws IOException {

super(file);

m_file = file;

}

public void close() throws IOException {

super.close();

if (m_file != null)

m_file.delete();

}

}

-

It's initiated like this:

public InputStream getInputStream() {

try {

return new TempFileInputStream(m_file);

rocketscienceguy at 2007-6-29 11:15:07 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3
Now that I think about it, my trouble starts before the native method, huh? Shucks. Still don't know what's wrong.
rocketscienceguy at 2007-6-29 11:15:07 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 4

I suggest you put in a few print statements to be sure which statement is failing.

One thing I notice is that you are passing in a File object, then using it to

o do file processing,

o be closed when you close the stream.

o do the delete.

try instantiating a separate File object (with the same path) and doing the delete.

bschauwe at 2007-6-29 11:15:07 > top of Java-index,Java HotSpot Virtual Machine,Specifications...