Guest User

Proxying InputStream

a guest
May 9th, 2012
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (let [reader (SequenceFile$Reader. file-system x hadoop-conf)
  2.               key (ReflectionUtils/newInstance (.. reader
  3.                                                    getKeyClass
  4.                                                    (asSubclass WritableComparable))
  5.                                                hadoop-conf)
  6.               value (ReflectionUtils/newInstance (.. reader
  7.                                                      getValueClass
  8.                                                      (asSubclass Writable))
  9.                                                  hadoop-conf)
  10.               inbuf (DataInputBuffer.)
  11.               outbuf (DataOutputBuffer.)]
  12.           (. stream close)
  13.           (proxy [InputStream] []
  14.             (read []
  15.               (if (or (nil? inbuf) (= (. inbuf read) -1))
  16.                 (if (not (. reader (next key value)))
  17.                   -1
  18.                   (do
  19.                     (let [tmp (.. key toString getBytes)]
  20.                       (doto outbuf
  21.                         (.write tmp 0 (. tmp length))
  22.                         (.write \tab)))
  23.                     (let [tmp (.. value toString getBytes)]
  24.                       (doto outbuf
  25.                         (.write tmp 0 (. tmp length))
  26.                         (.write \newline)))
  27.                     (. inbuf (reset (. outbuf getData)
  28.                                     (. outbuf getLength)))
  29.                     (. outbuf reset)
  30.                     (. read inbuf)))))))
Add Comment
Please, Sign In to add comment