私はClojureのに新たなんだと私はClojureのは、次のJavaコードと同等である私にとっては簡単な作業、実行する必要があります。(「RW」「ファイル」)のClojure - れるMappedByteBufferに(getChannel.mapによって返された)DirectByteBufferをキャストするにはどのように?
れるMappedByteBufferアウト=新しいのRandomAccessFileをさらに、getChannel( ).map(FileChannel.MapMode.READ_WRITE、0、100);
Clojureのは動的言語、地図である(ただし)はれるMappedByteBufferの代わりDirectByteBufferを返します。 MappedByteBufferのメンバーであるsetInt()メソッドを使用したいと思います。 Clojureに、DirectByteBufferの代わりにMappedByteBufferでメソッドを使用するよう指示する方法はありますか?
ありがとうございます!
ところで、これは私の試みです:ClojureのはDirectMapBufferに.setIntを探しているので
(defprotocol MfileP
(at [this pos])
(get-i [this])
(set-i [this val])
(resize [this size])
(fsize [this]))
(defrecord Mfile [fc buf] MfileP
(at [this pos] (.position buf pos))
(get-i [this] (.getInt buf))
(set-i [this val] (.setInt buf val))
(resize [this size] (assoc this :buf (.map fc FileChannel$MapMode/READ_WRITE 0 size)))
(fsize [this] (.size fc)))
(defn open [path]
(let [fc (.getChannel (new RandomAccessFile path "rw"))]
(let [buf (.map fc FileChannel$MapMode/READ_WRITE 0 (.size fc))]
(Mfile. fc buf))))
フォーム(設定-i)は、例外がスローされます。