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
v 3.0
(defn ^Charset charset
([s]
(Charset/forName s)))
link
(charset "UTF-8") => java.nio.charset.Charset
v 3.0
(defn charset:list
([]
(keys (Charset/availableCharsets))))
link
(charset-list) => ("Big5" "Big5-HKSCS" ... "x-windows-iso2022jp")
v 3.0
(defn input-stream?
([x]
(instance? InputStream x)))
link
(input-stream? (java.io.ByteArrayInputStream. (.getBytes "a"))) => true
v 3.0
(defn output-stream?
([x]
(instance? OutputStream x)))
link
(output-stream? (java.io.ByteArrayOutputStream.)) => 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:
- Character Set Utilities:n
charset:default: Returns the default character set of the system (e.g., "UTF-8").ncharset:list: Provides a list of all available character set names on the system.ncharset: Constructs ajava.nio.charset.Charsetobject from a given string name.nn2. I/O Type Predicates:ninput-stream?: Checks if an object is an instance ofjava.io.InputStream.noutput-stream?: Checks if an object is an instance ofjava.io.OutputStream.nreader?: Checks if an object is an instance ofjava.io.Reader.n *writer?: Checks if an object is an instance ofjava.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.