Package com.pi4j.io.file
Class LinuxFile
- java.lang.Object
-
- java.io.RandomAccessFile
-
- com.pi4j.io.file.LinuxFile
-
- All Implemented Interfaces:
Closeable,DataInput,DataOutput,AutoCloseable
public class LinuxFile extends RandomAccessFile
Extends RandomAccessFile to provide access to Linux ioctl.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLinuxFile.LinuxFileExceptionstatic classLinuxFile.ScratchBufferOverrun
-
Field Summary
Fields Modifier and Type Field Description static intlocalBufferSizestatic ThreadLocal<ByteBuffer>localDataBufferstatic ThreadLocal<IntBuffer>localOffsetsBufferstatic intwordSize
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static intdirectIOCTL(int fd, long command, int value)protected static intdirectIOCTLStructure(int fd, long command, ByteBuffer data, int dataOffset, IntBuffer offsetMap, int offsetMapOffset, int offsetCapacity)static interrno()protected voidfinalize()protected static intgetPosixFD(FileDescriptor fileDescriptor)voidioctl(long command, int value)Runs an ioctl value command on a file descriptor.voidioctl(long command, ByteBuffer data, IntBuffer offsets)Runs an ioctl on a file descriptor.static Stringstrerror(int code)-
Methods inherited from class java.io.RandomAccessFile
close, getChannel, getFD, getFilePointer, length, read, read, read, readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, seek, setLength, skipBytes, write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
-
-
-
-
Field Detail
-
wordSize
public static final int wordSize
-
localBufferSize
public static final int localBufferSize
- See Also:
- Constant Field Values
-
localDataBuffer
public static final ThreadLocal<ByteBuffer> localDataBuffer
-
localOffsetsBuffer
public static final ThreadLocal<IntBuffer> localOffsetsBuffer
-
-
Constructor Detail
-
LinuxFile
public LinuxFile(String name, String mode) throws FileNotFoundException
- Throws:
FileNotFoundException
-
-
Method Detail
-
ioctl
public void ioctl(long command, int value) throws IOExceptionRuns an ioctl value command on a file descriptor.- Parameters:
command- ioctl commandvalue- int ioctl value- Throws:
IOException
-
ioctl
public void ioctl(long command, ByteBuffer data, IntBuffer offsets) throws IOExceptionRuns an ioctl on a file descriptor. Uses special offset buffer to produce real C-like structures with pointers. Advanced use only! Must be able to produce byte-perfect data structures just as gcc would on this system, including struct padding and pointer size. The data ByteBuffer uses the current position to determine the head point of data passed to the ioctl. This is useful for appending entry-point data structures at the end of the buffer, while referring to other structures/data that come before them in the buffer. When assembling the structured data, usewordSizeto determine the size in bytes needed for a pointer. Also be sure to consider GCC padding and structure alignment. GCC will try a field to its word size (32b ints align at 4-byte, etc), and will align the structure size with the native word size (4-byte for 32b, 8-byte for 64b). Provided IntBuffer offsets must use native byte order (endianness).
DANGER: check your buffer length! The possible length varies depending on the ioctl call. Overruns are very possible. ioctl tries to determine EFAULTs, but sometimes you might trample JVM data if you are not careful.<NEED BETTER EXAMPLE HERE>- Parameters:
command- ioctl commanddata- values in bytes for all structures, with 4 or 8 byte size holes for pointersoffsets- byte offsets of pointer at given index- Throws:
IOException
-
finalize
protected void finalize() throws Throwable
-
errno
public static int errno()
-
strerror
public static String strerror(int code)
-
directIOCTL
protected static int directIOCTL(int fd, long command, int value)
-
directIOCTLStructure
protected static int directIOCTLStructure(int fd, long command, ByteBuffer data, int dataOffset, IntBuffer offsetMap, int offsetMapOffset, int offsetCapacity)
-
getPosixFD
protected static int getPosixFD(FileDescriptor fileDescriptor)
-
-