Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

make bencode throw IOExceptions as appropriate

  • Loading branch information...
commit f546a2ab4fc66325d177b1bd0bd632c5ab3923c9 1 parent 212de9c
@cemerick cemerick authored
Showing with 7 additions and 12 deletions.
  1. +7 −12 src/main/clojure/clojure/tools/nrepl/bencode.clj
View
19 src/main/clojure/clojure/tools/nrepl/bencode.clj
@@ -10,14 +10,10 @@
(ns #^{:author "Meikel Brandmeyer"
:doc "A netstring and bencode implementation for Clojure."}
clojure.tools.nrepl.bencode
- (:require
- [clojure.java.io :as io])
- (:import
- java.io.ByteArrayOutputStream
- java.io.InputStream
- java.io.OutputStream
- java.io.PushbackInputStream
- clojure.lang.RT))
+ (:require [clojure.java.io :as io])
+ (:import (java.io IOException ByteArrayOutputStream
+ InputStream OutputStream PushbackInputStream)
+ clojure.lang.RT))
;; # Motivation
;;
@@ -87,8 +83,7 @@
#^long [#^InputStream input]
(let [c (.read input)]
(when (neg? c)
- (throw
- (Exception. "Invalid netstring. Unexpected end of input.")))
+ (throw (IOException. "Invalid netstring. Unexpected end of input.")))
;; Here we have a quirk for example. `.read` returns -1 on end of
;; input. However the Java `Byte` has only a range from -128 to 127.
;; How does the fit together?
@@ -109,7 +104,7 @@
(let [result (.read input content offset len)]
(when (neg? result)
(throw
- (Exception.
+ (IOException.
"Invalid netstring. Less data available than expected.")))
(when (not= result len)
(recur (+ offset result) (- len result)))))
@@ -165,7 +160,7 @@
[input]
(let [content (read-netstring* input)]
(when (not= (read-byte input) comma)
- (throw (Exception. "Invalid netstring. ',' expected.")))
+ (throw (IOException. "Invalid netstring. ',' expected.")))
content))
;; Similarly the `string>payload` and `string<payload` functions
Please sign in to comment.
Something went wrong with that request. Please try again.