Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#27 MockFileInputStream not platform independent

open
nobody
None
5
2003-12-10
2003-12-10
Gino Marckx
No

Because a FileInputStream needs a real file to be
instantiated, the corresponding mock object also needs such
a file. For this reason, a KNOWN_FILE static member is
used, it is specified as C:/autoexec.bat
It is obvious that this only works on Windows, resulting in a
FileNotFound exception. If this public static member would
have been changeable, no problem, but it happens to be
final.
A better approach is to create a temp file and make sure it
is deleted upon shutdown of the VM.

Discussion

  • Logged In: NO

    An alternative would be to simply pass a FileDescriptor to
    the super constructor instead of creating a temp file. This
    should work platform independently:

    private MockFileInputStream() {
    // Unfortunately as there is no interface we have to
    call the supertype,
    // which requires a file.
    super(new FileDescriptor());
    }

    Can anyone integrate this into the current code?

    Regards,
    Florian.