Back

copy (clj)

(source)

function

(copy input output & opts)
Copies input to output. Returns nil or throws IOException. Input may be an InputStream, Reader, File, byte[], char[], or String. Output may be an OutputStream, Writer, or File. Options are key/value pairs and may be one of :buffer-size buffer size to use, default is 1024. :encoding encoding to use if converting between byte and char streams. Does not close any streams except those it opens itself (on a File).

Examples

quil/quil
(ns quil.snippets.image.pixels
  (:require #?(:clj [quil.snippets.macro :refer [defsnippet]])
            [quil.core :as q :include-macros true]
            quil.snippets.all-snippets-internal
            #?(:clj [clojure.java.io :as io]))
  #?(:cljs
     (:use-macros [quil.snippets.macro :only [defsnippet]])))

(defsnippet copy
  "copy"
  {}

    (comment "draw original image")
    (q/image im 0 0)
    (comment "copy left top quarter to the right top quarter")
    (q/copy im im [0 0 50 50] [50 0 50 50])
    (comment "copy the whole image to the sketch, essentially just draw it")
    (q/copy im [0 0 100 100] [120 0 100 100])
    (comment "copy top left 50x50 square of sketch ")
    (comment "to the 100x100 square at [240, 0] position")
    (q/copy [0 0 50 50] [240 0 100 100]))

    (comment "copy graphics and draw it")
    (q/image (q/get-pixel gr) 0 120)

    (comment "use get-pixel to copy part of the graphics")
    (q/image (q/get-pixel gr 0 0 50 50) 240 120)

    (comment "use get-pixel to copy part of the sketch itself")
    (q/image (q/get-pixel) 400 400)
    (q/fill (q/get-pixel 50 50))
    (q/rect 120 240 100 100)
    (q/image (q/get-pixel 0 0 50 50) 240 240))

    (q/background 255)
    (comment "draw original graphics")
    (q/image gr 0 0)
    (comment "get pixels of the graphics and copy")
    (comment "the first half of all pixels to the second half")
    (let [px (q/pixels gr)
          half #?(:clj (/ (* size size) 2)
                  :cljs (* 4 (* (q/display-density) size) (/ (* (q/display-density) size) 2)))]
      (dotimes [i half]
        #?(:clj (aset-int px (+ i half) (aget px i))
           :cljs (aset px (+ i half) (aget px i)))))
    (q/update-pixels gr)
    (q/image gr (+ size 20) 0)

    (comment "get pixels of the sketch itself and copy")
    (comment "the first half of all pixels to the second half")
    (let [px (q/pixels)
          half #?(:clj (/ (* (q/width) (q/height)) 10)
                  :cljs (/ (* 4 (* (q/display-density) (q/width)) (* (q/display-density) (q/height))) 10))]
      (dotimes [i half]
        #?(:clj (aset-int px (+ i half) (aget px i))
           :cljs (aset px (+ i half) (aget px i)))))
    (q/update-pixels)
    (q/no-loop)))
cljsjs/packages
(require '[cljsjs.boot-cljsjs.packaging :refer :all]
         '[boot.core :as boot]
         '[boot.tmpdir :as tmpd]
         '[clojure.java.io :as io]
         '[boot.util :refer [sh]])

(deftask build-emoji-mart []
  (let [tmp (boot/tmp-dir!)]
    (with-pre-wrap
      fileset
      ;; Copy all files in fileset to temp directory
      (doseq [f (->> fileset boot/input-files)
              :let [target (io/file tmp (tmpd/path f))]]
        (io/make-parents target)
        (io/copy (tmpd/file f) target))
      (binding [boot.util/*sh-dir* (str (io/file tmp (format "emoji-mart-%s" +lib-version+)))]
        ((sh "npm" "install"))
        ((sh "npm" "run" "clean"))
        ((sh "npm" "run" "build:data"))
        ((sh "npm" "run" "build:dist"))
        ((sh "npm" "install" "browserify"))
        ((sh "node" "node_modules/browserify/bin/cmd.js" "--debug" "-u" "react" "dist/index.js" "-s" "EmojiMart" "-o" "dist/emoji-mart.js"))
        ((sh "sed" "-i.bak" "/var React = /d" "dist/emoji-mart.js"))
        ((sh "sed" "-i.bak" "s/var _react = .*/var _react = React;/" "dist/emoji-mart.js")))
      (-> fileset (boot/add-resource tmp) boot/commit!))))
cljsjs/packages
(require '[cljsjs.boot-cljsjs.packaging :refer :all]
         '[boot.core :as boot]
         '[boot.tmpdir :as tmpd]
         '[clojure.java.io :as io]
         '[boot.util :refer [sh]])

(deftask build-msgpack-lite []
  (let [tmp (boot/tmp-dir!)]
    (with-pre-wrap
      fileset
      ;; Copy all files in fileset to temp directory
      (doseq [f (->> fileset boot/input-files)
              :let [target (io/file tmp (tmpd/path f))]]
        (io/make-parents target)
        (io/copy (tmpd/file f) target))
      (binding [boot.util/*sh-dir* (str (io/file tmp (format "msgpack-lite-%s" +lib-version+)))]
        (dosh "npm" "install")
        (dosh "./node_modules/.bin/browserify" "--debug" "--standalone" "msgpack" "./lib/browser.js" "--outfile" "./dist/msgpack.browserify.js"))
      (-> fileset (boot/add-resource tmp) boot/commit!))))
cljsjs/packages
(require '[boot.core :as c]
         '[boot.util :as util]
         '[clojure.java.io :as io])

(deftask build []
  (let [tmp          (c/tmp-dir!)
        +lib-folder+ (str "react-autosize-textarea-" +lib-version+)
        webpack-cfg  "webpack.config.dist.js"]
    (with-pre-wrap fileset
      (doseq [f    (c/input-files fileset)
              :let [target (io/file tmp (c/tmp-path f))]]
        (io/make-parents target)
        (io/copy (c/tmp-file f) target))
      (io/make-parents (io/file tmp +lib-folder+ "dist"))
      (io/copy
       (c/tmp-file (first (c/by-name [webpack-cfg] (c/input-files fileset))))
       (io/file tmp +lib-folder+ webpack-cfg))
      (binding [util/*sh-dir* (str (io/file tmp +lib-folder+))]
        ((sh "npm" "install" "--ignore-scripts"))
        ((sh "npm" "install" "--save-dev" "typescript@2.7.2 ts-loader@4.1.0 webpack-cli@4.4.1"))
        ((sh "./node_modules/.bin/webpack" "--config" "webpack.config.dist.js")))
      (-> fileset
          (c/add-resource (io/file tmp +lib-folder+ "dist"))
          c/commit!))))
aliostad/deep-learning-lang-detection
(ns propS3t.test.core
  (:refer-clojure :exclude [key])
  (:load "aws") ;; aws credentials and test bucket name
  (:use [propS3t.core]
        [clojure.test])
  (:require [clojure.java.io :as io])
  (:import (java.util UUID)
           (java.io ByteArrayInputStream
                    ByteArrayOutputStream)))

  (deftest t-multipart-upload
    (let [{:keys [upload-id key bucket] :as mp}
          (start-multipart *creds* test-bucket "multipart-test")]
      (is (and upload-id key bucket))
      (is (= test-bucket bucket))
      (is (= key "multipart-test"))
      (let [five-megs (.getBytes (apply str (repeat (* 5 1024 1024) \a)))
            tags (doall (pmap #(write-part *creds* mp (inc %)
                                           (ByteArrayInputStream. five-megs)
                                           :length (count five-megs))
                              (range 2)))]
        (end-multipart *creds* mp test-bucket "multipart-test" tags)
        (with-open [baos (ByteArrayOutputStream.)]
          (io/copy (read-stream *creds* test-bucket "multipart-test")
                   baos)
          (is (= (* 2 (count five-megs)) (count (.toByteArray baos))))))))
  )

(deftest t-read-stream
  (is (write-stream *creds* test-bucket "write-stream-test"
                    (ByteArrayInputStream.
                     (.getBytes "hello world"))
                    :length 11))
  (with-open [baos (ByteArrayOutputStream.)]
    (io/copy (read-stream *creds* test-bucket "write-stream-test")
             baos)
    (is (= "hello world" (String. (.toByteArray baos)))))
  (with-open [baos (ByteArrayOutputStream.)]
    (io/copy (read-stream *creds* test-bucket "write-stream-test"
                          :offset 6)
             baos)
    (is (= "world" (String. (.toByteArray baos)))))
  (with-open [baos (ByteArrayOutputStream.)]
    (io/copy (read-stream *creds* test-bucket "write-stream-test"
                          :length 9
                          :offset 6)
             baos)
    (is (= "worl" (String. (.toByteArray baos)))))
  (with-open [baos (ByteArrayOutputStream.)]
    (io/copy (read-stream *creds* test-bucket "write-stream-test"
                          :length 4)
             baos)
    (is (= "hello" (String. (.toByteArray baos))))))

(deftest t-output-stream
  (with-open [s (output-stream *creds* test-bucket "write-stream2-test"
                               :length 5)]
    (io/copy (.getBytes "hello") s))
  (is (contains? (set (map :key (list-bucket *creds* test-bucket "" 1000)))
                 "write-stream2-test"))
  (with-open [baos (ByteArrayOutputStream.)
              stream (read-stream *creds* test-bucket "write-stream2-test")]
    (io/copy stream baos)
    (is (= "hello" (String. (.toByteArray baos))))))