Class FileIo
The file-system calls a static handler needs, isolated so that everything else
in StaticFiles -- ranges, conditional requests, MIME types, the containment
check -- is pure Java and shared by every target. That logic is the part worth
getting right once.
There is one of these per target: the translated one goes to open/fstat/sendfile directly, the Java SE one to the JDK's channels.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intopenBeneath cannot answer here; fall back to open plus a resolved-path check.static final intopenRead: the file is there and could not be opened. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidclose(int fd) static booleanTrue whensendFile(int, int, long, long)is a kernel copy rather than a read/write loop.static intopenBeneath(String root, String relative) A descriptor forrelativeunderroot, or -1.static intstatic intread(int fd, byte[] buffer, int offset, int length) static StringThe canonical path, symlinks followed.static longsendFile(int socketFd, int fileFd, long offset, long count) Sends bytes from a file straight to a socket, without them entering this process where the platform allows it.static intstat(int fd, long[] out) Fills out[0]=size, out[1]=modified-time-millis, out[2]=1 for a directory.static intstatFresh(int fd, long[] out) The same call, because statImpl is a live fstat on the open descriptor and so is already current.
-
Field Details
-
BENEATH_UNSUPPORTED
public static final int BENEATH_UNSUPPORTEDopenBeneath cannot answer here; fall back to open plus a resolved-path check.- See Also:
-
OPEN_FAILED
public static final int OPEN_FAILEDopenRead: the file is there and could not be opened. See openReadImpl.- See Also:
-
-
Method Details
-
openBeneath
A descriptor for
relativeunderroot, or -1. Never a file outsideroot, and never by checking afterwards: the kernel refuses the escape while it resolves, so there is no window between the open and the check for a symlink to move through.Returns
BENEATH_UNSUPPORTEDwhere the platform has no such call, so the caller can fall back rather than treat it as a missing file. -
openRead
-
stat
public static int stat(int fd, long[] out) Fills out[0]=size, out[1]=modified-time-millis, out[2]=1 for a directory. Taken from the OPEN DESCRIPTOR rather than the path: stat-then-open lets the file change in between, which is how a length header ends up disagreeing with the body. -
statFresh
public static int statFresh(int fd, long[] out) The same call, because statImpl is a live fstat on the open descriptor and so is already current.
It exists so the two runtimes present one API: the Java SE implementation answers stat() from an open-time snapshot that asset serving needs, and therefore cannot answer whether the file has changed since. See the javadoc there.
-
sendFile
public static long sendFile(int socketFd, int fileFd, long offset, long count) Sends bytes from a file straight to a socket, without them entering this process where the platform allows it. Returns how many moved, which may be fewer than asked; the caller loops. -
hasSendFile
public static boolean hasSendFile()True whensendFile(int, int, long, long)is a kernel copy rather than a read/write loop. -
read
public static int read(int fd, byte[] buffer, int offset, int length) -
realPath
-
close
public static void close(int fd)
-