@@ -48,13 +48,64 @@ public RawCanChannel(SelectorProvider provider, int sock) {
4848
4949 public abstract RawCanChannel bind (NetworkDevice device ) throws IOException ;
5050
51+ /**
52+ * Reads a CAM frame from the channel by internally allocating a new direct {@link ByteBuffer}.
53+ *
54+ * @return the CAN frame
55+ * @throws IOException if the IO operations failed or invalid data was read.
56+ */
5157 public abstract CanFrame read () throws IOException ;
58+
59+ /**
60+ * Reads a CAM frame from the channel using the supplied buffer.
61+ *
62+ * @param buffer the buffer to read into.The buffer's {@link ByteOrder} will be set to native and it will be
63+ * flipped after the read has been completed.
64+ * @return the CAN frame
65+ * @throws IOException if the IO operations failed, the supplied buffer was insufficient or invalid data was read.
66+ */
5267 public abstract CanFrame read (ByteBuffer buffer ) throws IOException ;
68+
69+ /**
70+ * Reads raw bytes from the channel.
71+ *
72+ * This method does not apply any checks on the data that has been read or on the supplied buffer. This method
73+ * is primarily intended for downstream libraries that implement their own parsing on the data from the socket.
74+ *
75+ * @param buffer the buffer to read into.The buffer's {@link ByteOrder} will be set to native and it will be
76+ * flipped after the read has been completed.
77+ * @return the number of bytes
78+ * @throws IOException if the IO operations failed.
79+ */
80+ public abstract long readUnsafe (ByteBuffer buffer ) throws IOException ;
81+
82+ /**
83+ * Writes the given CAN frame.
84+ *
85+ * @param frame the frame to be written.
86+ * @return fluent interface.
87+ * @throws IOException if the IO operations failed.
88+ */
5389 public abstract RawCanChannel write (CanFrame frame ) throws IOException ;
5490
91+ /**
92+ * Writes the given buffer in its entirety to the socket.
93+ *
94+ * This method does not apply any checks on the given buffer. This method is primarily intended for downstream libraries
95+ * that create these buffers using other facilities.
96+ *
97+ * @param buffer the buffer to be written.
98+ * @return the bytes written.
99+ * @throws IOException if the IO operations failed.
100+ */
101+ public abstract long writeUnsafe (ByteBuffer buffer ) throws IOException ;
102+
103+ /**
104+ * Allocates a buffer that is large enough to hold any supported CAN frame.
105+ *
106+ * @return a new buffer ready to be used.
107+ */
55108 public static ByteBuffer allocateSufficientMemory () {
56- ByteBuffer buf = ByteBuffer .allocateDirect (FD_MTU + 1 );
57- buf .order (ByteOrder .nativeOrder ());
58- return buf ;
109+ return JavaCAN .allocateOrdered (FD_MTU + 1 );
59110 }
60111}
0 commit comments