Created
February 23, 2015 20:19
-
-
Save antekone/1ef796d1f0f3121c6063 to your computer and use it in GitHub Desktop.
512_8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns s512.core | |
(:require [clojure.java.io :as io]) | |
(:gen-class)) | |
(set! *warn-on-reflection* true) | |
(defn data-file [] | |
(io/file "out.bin")) | |
(defn data-stream [] | |
(io/input-stream (data-file))) | |
(defn output-data-stream [] | |
(java.io.BufferedOutputStream. (java.io.FileOutputStream. (java.io.File. "stripped")))) | |
(defn data-stream-size [] | |
(.length (java.io.File. "out.bin"))) | |
(defn filter-sector [arr warr] | |
(loop [arr-idx 0 warr-idx 0] | |
(if (or (> warr-idx (- (count warr) 512)) | |
(> arr-idx (- (count arr) 512))) | |
0 | |
(do | |
(System/arraycopy arr arr-idx warr warr-idx 512) | |
(recur (+ arr-idx 512 8) (+ warr-idx 512)))))) | |
(defn process [^java.io.InputStream in-stream ^java.io.BufferedOutputStream out-stream] | |
(let [javabuf (make-array Byte/TYPE (* 1000 520)) | |
javabuf2 (make-array Byte/TYPE (* 1000 520))] | |
(loop [ofs 0] | |
(if (= -1 (.read in-stream javabuf)) | |
0 | |
(do | |
(filter-sector javabuf javabuf2) | |
(.write out-stream javabuf2) | |
(recur (+ ofs (count javabuf)))))))) | |
(defn r [] (use 's512.core :reload)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment