1    Introduction

1.1    Overview

std.lib.io is part of the standard foundation library set. This page collects the public API reference for the namespace.

2    Walkthrough

2.1    Charsets

std.lib.io provides helpers for working with character sets and checking I/O object types.

get the default charset

^{:refer std.lib.io/charset:default :added "3.0"}
(charset:default)
=> "UTF-8"

2.2    I/O type predicates

The predicates distinguish the four main I/O object types.

check I/O object types

^{:refer std.lib.io/input-stream? :added "3.0"}
(input-stream? (java.io.ByteArrayInputStream. (.getBytes "a")))
=> true

^{:refer std.lib.io/output-stream? :added "3.0"}
(output-stream? (java.io.ByteArrayOutputStream.))
=> true

^{:refer std.lib.io/reader? :added "3.0"}
(reader? (java.io.StringReader. "a"))
=> true

^{:refer std.lib.io/writer? :added "3.0"}
(writer? (java.io.StringWriter.))
=> true

3    API



charset ^

[s]
Added 3.0

constructs a charset object from a string

v 3.0
(defn ^Charset charset
  ([s]
   (Charset/forName s)))
link
(charset "UTF-8") => java.nio.charset.Charset

charset:default ^

[]
Added 3.0

returns the default charset

v 3.0
(defn charset:default
  ([]
   (str (Charset/defaultCharset))))
link
(charset:default) => "UTF-8"

charset:list ^

[]
Added 3.0

returns the list of available charset

v 3.0
(defn charset:list
  ([]
   (keys (Charset/availableCharsets))))
link
(charset-list) => ("Big5" "Big5-HKSCS" ... "x-windows-iso2022jp")

input-stream? ^

[x]
Added 3.0

checks if object is an input-stream

v 3.0
(defn input-stream?
  ([x]
   (instance? InputStream x)))
link
(input-stream? (java.io.ByteArrayInputStream. (.getBytes "a"))) => true

output-stream? ^

[x]
Added 3.0

checks if object is an output-stream

v 3.0
(defn output-stream?
  ([x]
   (instance? OutputStream x)))
link
(output-stream? (java.io.ByteArrayOutputStream.)) => true

reader? ^

[x]
Added 3.0

checks that object is a reader

v 3.0
(defn reader?
  ([x]
   (instance? Reader x)))
link
(reader? (java.io.StringReader. "a")) => true

writer? ^

[x]
Added 3.0

checks that object is a writer

v 3.0
(defn writer?
  ([x]
   (instance? Writer x)))
link
(writer? (java.io.StringWriter.)) => true

4    std.lib.io: A Comprehensive Summary

The std.lib.io namespace provides fundamental utilities for working with I/O operations in Clojure, primarily focusing on character sets and type predicates for various I/O stream and reader/writer types. It offers functions to query and manipulate character sets and to check the type of I/O-related objects.

Key Features and Concepts:

  1. Character Set Utilities:n charset:default: Returns the default character set of the system (e.g., "UTF-8").n charset:list: Provides a list of all available character set names on the system.n charset: Constructs a java.nio.charset.Charset object from a given string name.nn2. I/O Type Predicates:n input-stream?: Checks if an object is an instance of java.io.InputStream.n output-stream?: Checks if an object is an instance of java.io.OutputStream.n reader?: Checks if an object is an instance of java.io.Reader.n * writer?: Checks if an object is an instance of java.io.Writer.

Usage and Importance:

The std.lib.io module is a foundational component for any Clojure application that deals with file operations, network communication, or any form of data input/output. It provides basic tools for ensuring correct character encoding and for type-checking I/O objects, which can be crucial for robust and error-free I/O handling. While simple, these utilities are essential for building more complex I/O functionalities within the foundation-base project.