ndnboost: Include boost::iostreams for internal use.
diff --git a/include/ndnboost/iostreams/detail/adapter/concept_adapter.hpp b/include/ndnboost/iostreams/detail/adapter/concept_adapter.hpp
new file mode 100644
index 0000000..d182bee
--- /dev/null
+++ b/include/ndnboost/iostreams/detail/adapter/concept_adapter.hpp
@@ -0,0 +1,287 @@
+// (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
+// (C) Copyright 2003-2007 Jonathan Turkanis
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
+
+// See http://www.boost.org/libs/iostreams for documentation.
+
+#ifndef NDNBOOST_IOSTREAMS_DETAIL_CONCEPT_ADAPTER_HPP_INCLUDED
+#define NDNBOOST_IOSTREAMS_DETAIL_CONCEPT_ADAPTER_HPP_INCLUDED
+
+#include <ndnboost/config.hpp>                             // SFINAE.
+#include <ndnboost/iostreams/concepts.hpp>
+#include <ndnboost/iostreams/categories.hpp>
+#include <ndnboost/iostreams/detail/adapter/non_blocking_adapter.hpp>
+#include <ndnboost/iostreams/detail/call_traits.hpp>
+#include <ndnboost/iostreams/detail/char_traits.hpp>
+#include <ndnboost/iostreams/detail/dispatch.hpp>
+#include <ndnboost/iostreams/detail/error.hpp>
+#include <ndnboost/iostreams/detail/streambuf.hpp>        // pubsync.
+#include <ndnboost/iostreams/detail/config/unreachable_return.hpp>
+#include <ndnboost/iostreams/device/null.hpp>
+#include <ndnboost/iostreams/traits.hpp>
+#include <ndnboost/iostreams/operations.hpp>
+#include <ndnboost/mpl/if.hpp>
+#include <ndnboost/static_assert.hpp>
+#include <ndnboost/throw_exception.hpp>
+
+// Must come last.
+#include <ndnboost/iostreams/detail/config/disable_warnings.hpp>  // MSVC.
+
+
+namespace ndnboost { namespace iostreams { namespace detail {
+
+template<typename Category> struct device_wrapper_impl;
+template<typename Category> struct flt_wrapper_impl;
+
+template<typename T>
+class concept_adapter {
+private:
+    typedef typename detail::value_type<T>::type       value_type;
+    typedef typename dispatch<T, input, output>::type  input_tag;
+    typedef typename dispatch<T, output, input>::type  output_tag;
+    typedef typename
+            mpl::if_<
+                is_device<T>,
+                device_wrapper_impl<input_tag>,
+                flt_wrapper_impl<input_tag>
+            >::type                                    input_impl;
+    typedef typename
+            mpl::if_<
+                is_device<T>,
+                device_wrapper_impl<output_tag>,
+                flt_wrapper_impl<output_tag>
+            >::type                                    output_impl;
+    typedef typename
+            mpl::if_<
+                is_device<T>,
+                device_wrapper_impl<any_tag>,
+                flt_wrapper_impl<any_tag>
+            >::type                                    any_impl;
+public:
+    typedef typename char_type_of<T>::type             char_type;
+    typedef typename category_of<T>::type              category;
+
+    explicit concept_adapter(const reference_wrapper<T>& ref) : t_(ref.get())
+    { NDNBOOST_STATIC_ASSERT(is_std_io<T>::value); }
+    explicit concept_adapter(const T& t) : t_(t)
+    { NDNBOOST_STATIC_ASSERT(!is_std_io<T>::value); }
+
+    T& operator*() { return t_; }
+    T* operator->() { return &t_; }
+
+    std::streamsize read(char_type* s, std::streamsize n)
+    { return this->read(s, n, (basic_null_source<char_type>*) 0); }
+
+    template<typename Source>
+    std::streamsize read(char_type* s, std::streamsize n, Source* src)
+    { return input_impl::read(t_, src, s, n); }
+
+    std::streamsize write(const char_type* s, std::streamsize n)
+    { return this->write(s, n, (basic_null_sink<char_type>*) 0); }
+
+    template<typename Sink>
+    std::streamsize write(const char_type* s, std::streamsize n, Sink* snk)
+    { return output_impl::write(t_, snk, s, n); }
+
+    std::streampos seek( stream_offset off, NDNBOOST_IOS::seekdir way,
+                         NDNBOOST_IOS::openmode which )
+    { 
+        return this->seek( off, way, which, 
+                           (basic_null_device<char_type, seekable>*) 0); 
+    }
+
+    template<typename Device>
+    std::streampos seek( stream_offset off, NDNBOOST_IOS::seekdir way,
+                         NDNBOOST_IOS::openmode which, Device* dev )
+    { return any_impl::seek(t_, dev, off, way, which); }
+
+    void close(NDNBOOST_IOS::openmode which)
+    { this->close(which, (basic_null_device<char_type, seekable>*) 0); }
+
+    template<typename Device>
+    void close(NDNBOOST_IOS::openmode which, Device* dev)
+    { any_impl::close(t_, dev, which); }
+
+    template<typename Device>
+    bool flush( Device* dev )
+    {
+        bool result = any_impl::flush(t_, dev);
+        if (dev && dev->NDNBOOST_IOSTREAMS_PUBSYNC() == -1)
+            result = false;
+        return result;
+    }
+
+    template<typename Locale> // Avoid dependency on <locale>
+    void imbue(const Locale& loc) { iostreams::imbue(t_, loc); }
+
+    std::streamsize optimal_buffer_size() const
+    { return iostreams::optimal_buffer_size(t_); }
+public:
+    concept_adapter& operator=(const concept_adapter&);
+    value_type t_;
+};
+
+//------------------Specializations of device_wrapper_impl--------------------//
+
+template<>
+struct device_wrapper_impl<any_tag> {
+    template<typename Device, typename Dummy>
+    static std::streampos 
+    seek( Device& dev, Dummy*, stream_offset off, 
+          NDNBOOST_IOS::seekdir way, NDNBOOST_IOS::openmode which )
+    { 
+        typedef typename category_of<Device>::type category;
+        return seek(dev, off, way, which, category()); 
+    }
+
+    template<typename Device>
+    static std::streampos 
+    seek( Device&, stream_offset, NDNBOOST_IOS::seekdir, 
+          NDNBOOST_IOS::openmode, any_tag )
+    { 
+        ndnboost::throw_exception(cant_seek());
+        NDNBOOST_IOSTREAMS_UNREACHABLE_RETURN(0)
+    }
+
+    template<typename Device>
+    static std::streampos 
+    seek( Device& dev, stream_offset off, 
+          NDNBOOST_IOS::seekdir way, NDNBOOST_IOS::openmode which, 
+          random_access )
+    { 
+        return iostreams::seek(dev, off, way, which); 
+    }
+
+    template<typename Device, typename Dummy>
+    static void close(Device& dev, Dummy*, NDNBOOST_IOS::openmode which)
+    { iostreams::close(dev, which); }
+
+    template<typename Device, typename Dummy>
+    static bool flush(Device& dev, Dummy*)
+    { return iostreams::flush(dev); }
+};
+
+
+template<>
+struct device_wrapper_impl<input> : device_wrapper_impl<any_tag>  {
+    template<typename Device, typename Dummy>
+    static std::streamsize
+    read( Device& dev, Dummy*, typename char_type_of<Device>::type* s,
+          std::streamsize n )
+    { return iostreams::read(dev, s, n); }
+
+    template<typename Device, typename Dummy>
+    static std::streamsize 
+    write( Device&, Dummy*, const typename char_type_of<Device>::type*,
+           std::streamsize )
+    { ndnboost::throw_exception(cant_write());
+      NDNBOOST_IOSTREAMS_UNREACHABLE_RETURN(0) }
+};
+
+template<>
+struct device_wrapper_impl<output> {
+    template<typename Device, typename Dummy>
+    static std::streamsize
+    read(Device&, Dummy*, typename char_type_of<Device>::type*, std::streamsize)
+    { ndnboost::throw_exception(cant_read());
+      NDNBOOST_IOSTREAMS_UNREACHABLE_RETURN(0) }
+
+    template<typename Device, typename Dummy>
+    static std::streamsize 
+    write( Device& dev, Dummy*, const typename char_type_of<Device>::type* s,
+           std::streamsize n )
+    { return iostreams::write(dev, s, n); }
+};
+
+//------------------Specializations of flt_wrapper_impl--------------------//
+
+template<>
+struct flt_wrapper_impl<any_tag> {
+    template<typename Filter, typename Device>
+    static std::streampos
+    seek( Filter& f, Device* dev, stream_offset off,
+          NDNBOOST_IOS::seekdir way, NDNBOOST_IOS::openmode which )
+    {
+        typedef typename category_of<Filter>::type category;
+        return seek(f, dev, off, way, which, category());
+    }
+
+    template<typename Filter, typename Device>
+    static std::streampos
+    seek( Filter&, Device*, stream_offset,
+          NDNBOOST_IOS::seekdir, NDNBOOST_IOS::openmode, any_tag )
+    { ndnboost::throw_exception(cant_seek());
+      NDNBOOST_IOSTREAMS_UNREACHABLE_RETURN(0) }
+
+    template<typename Filter, typename Device>
+    static std::streampos
+    seek( Filter& f, Device* dev, stream_offset off,
+          NDNBOOST_IOS::seekdir way, NDNBOOST_IOS::openmode which,
+          random_access tag )
+    {
+        typedef typename category_of<Filter>::type category;
+        return seek(f, dev, off, way, which, tag, category());
+    }
+
+    template<typename Filter, typename Device>
+    static std::streampos
+    seek( Filter& f, Device* dev, stream_offset off,
+          NDNBOOST_IOS::seekdir way, NDNBOOST_IOS::openmode,
+          random_access, any_tag )
+    { return f.seek(*dev, off, way); }
+
+    template<typename Filter, typename Device>
+    static std::streampos
+    seek( Filter& f, Device* dev, stream_offset off,
+          NDNBOOST_IOS::seekdir way, NDNBOOST_IOS::openmode which,
+          random_access, two_sequence )
+    { return f.seek(*dev, off, way, which);  }
+
+    template<typename Filter, typename Device>
+    static void close(Filter& f, Device* dev, NDNBOOST_IOS::openmode which)
+    { iostreams::close(f, *dev, which); }
+
+    template<typename Filter, typename Device>
+    static bool flush(Filter& f, Device* dev)
+    { return iostreams::flush(f, *dev); }
+};
+
+template<>
+struct flt_wrapper_impl<input> {
+    template<typename Filter, typename Source>
+    static std::streamsize
+    read( Filter& f, Source* src, typename char_type_of<Filter>::type* s,
+          std::streamsize n )
+    { return iostreams::read(f, *src, s, n); }
+
+    template<typename Filter, typename Sink>
+    static std::streamsize 
+    write( Filter&, Sink*, const typename char_type_of<Filter>::type*, 
+           std::streamsize )
+    { ndnboost::throw_exception(cant_write());
+      NDNBOOST_IOSTREAMS_UNREACHABLE_RETURN(0) }
+};
+
+template<>
+struct flt_wrapper_impl<output> {
+    template<typename Filter, typename Source>
+    static std::streamsize
+    read(Filter&, Source*, typename char_type_of<Filter>::type*,std::streamsize)
+    { ndnboost::throw_exception(cant_read());
+      NDNBOOST_IOSTREAMS_UNREACHABLE_RETURN(0) }
+
+    template<typename Filter, typename Sink>
+    static std::streamsize 
+    write( Filter& f, Sink* snk, const typename char_type_of<Filter>::type* s,
+           std::streamsize n )
+    { return iostreams::write(f, *snk, s, n); }
+};
+
+//----------------------------------------------------------------------------//
+
+} } } // End namespaces detail, iostreams, boost.
+
+#include <ndnboost/iostreams/detail/config/enable_warnings.hpp>  // MSVC.
+
+#endif // #ifndef NDNBOOST_IOSTREAMS_DETAIL_CONCEPT_ADAPTER_HPP_INCLUDED
diff --git a/include/ndnboost/iostreams/detail/adapter/device_adapter.hpp b/include/ndnboost/iostreams/detail/adapter/device_adapter.hpp
new file mode 100644
index 0000000..aa82c7a
--- /dev/null
+++ b/include/ndnboost/iostreams/detail/adapter/device_adapter.hpp
@@ -0,0 +1,67 @@
+/*
+ * Defines the class template ndnboost::iostreams::detail::device_adapter,
+ * a convenience base class for device adapters.
+ *
+ * File:        ndnboost/iostreams/detail/adapter/filter_adapter.hpp
+ * Date:        Mon Nov 26 14:35:48 MST 2007
+ * 
+ * Copyright:   2007-2008 CodeRage, LLC
+ * Author:      Jonathan Turkanis
+ * Contact:     turkanis at coderage dot com
+ *
+ * Distributed under the Boost Software License, Version 1.0.(See accompanying 
+ * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
+ * 
+ * See http://www.boost.org/libs/iostreams for documentation.
+ */
+
+#ifndef NDNBOOST_IOSTREAMS_DETAIL_DEVICE_ADAPTER_HPP_INCLUDED
+#define NDNBOOST_IOSTREAMS_DETAIL_DEVICE_ADAPTER_HPP_INCLUDED
+
+#include <ndnboost/iostreams/categories.hpp>
+#include <ndnboost/iostreams/detail/call_traits.hpp>
+#include <ndnboost/iostreams/detail/ios.hpp>
+#include <ndnboost/iostreams/operations.hpp>
+#include <ndnboost/iostreams/traits.hpp>
+#include <ndnboost/static_assert.hpp>
+
+namespace ndnboost { namespace iostreams { namespace detail {
+
+template<typename T>
+class device_adapter {
+private:
+    typedef typename detail::value_type<T>::type value_type;
+    typedef typename detail::param_type<T>::type param_type;
+public:
+    explicit device_adapter(param_type t) : t_(t) { }
+    T& component() { return t_; }
+
+    void close() 
+    {
+        detail::close_all(t_);
+    }
+
+    void close(NDNBOOST_IOS::openmode which) 
+    { 
+        iostreams::close(t_, which); 
+    }
+
+    bool flush() 
+    { 
+        return iostreams::flush(t_); 
+    }
+
+    template<typename Locale> // Avoid dependency on <locale>
+    void imbue(const Locale& loc) { iostreams::imbue(t_, loc); }
+
+    std::streamsize optimal_buffer_size() const 
+    { return iostreams::optimal_buffer_size(t_); }
+public:
+    value_type t_;
+};
+
+//----------------------------------------------------------------------------//
+
+} } } // End namespaces detail, iostreams, boost.
+
+#endif // #ifndef NDNBOOST_IOSTREAMS_DETAIL_DEVICE_ADAPTER_HPP_INCLUDED
diff --git a/include/ndnboost/iostreams/detail/adapter/direct_adapter.hpp b/include/ndnboost/iostreams/detail/adapter/direct_adapter.hpp
new file mode 100644
index 0000000..99eebf9
--- /dev/null
+++ b/include/ndnboost/iostreams/detail/adapter/direct_adapter.hpp
@@ -0,0 +1,281 @@
+// (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
+// (C) Copyright 2003-2007 Jonathan Turkanis
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
+
+// See http://www.boost.org/libs/iostreams for documentation.
+
+#ifndef NDNBOOST_IOSTREAMS_DETAIL_DIRECT_ADAPTER_HPP_INCLUDED
+#define NDNBOOST_IOSTREAMS_DETAIL_DIRECT_ADAPTER_HPP_INCLUDED
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+# pragma once
+#endif              
+
+#include <ndnboost/config.hpp>       // SFINAE, MSVC, put ptrdiff_t in std.
+#include <algorithm>              // copy, min.
+#include <cstddef>                // ptrdiff_t.
+#include <ndnboost/detail/workaround.hpp>
+#include <ndnboost/iostreams/categories.hpp>
+#include <ndnboost/iostreams/detail/config/limits.hpp>        // forwarding.
+#include <ndnboost/iostreams/detail/config/wide_streams.hpp>  // locale.
+#include <ndnboost/iostreams/detail/double_object.hpp>
+#include <ndnboost/iostreams/detail/error.hpp>
+#include <ndnboost/iostreams/detail/ios.hpp>  // openmode, seekdir, int types.
+#include <ndnboost/iostreams/traits.hpp>      // mode_of, is_direct.
+#include <ndnboost/iostreams/operations.hpp>
+#include <ndnboost/mpl/bool.hpp> 
+#include <ndnboost/mpl/or.hpp> 
+#include <ndnboost/preprocessor/iteration/local.hpp>
+#include <ndnboost/preprocessor/repetition/enum_binary_params.hpp>
+#include <ndnboost/preprocessor/repetition/enum_params.hpp>
+#include <ndnboost/static_assert.hpp>
+#include <ndnboost/throw_exception.hpp>
+#include <ndnboost/type_traits/is_convertible.hpp>
+
+// Must come last.
+#include <ndnboost/iostreams/detail/config/disable_warnings.hpp> // VC7.1
+
+namespace ndnboost { namespace iostreams { namespace detail {
+                    
+//------------------Definition of direct_adapter_base-------------------------//
+
+// Put all initialization in base class to faciliate forwarding.
+template<typename Direct>
+class direct_adapter_base {
+public:
+    typedef typename char_type_of<Direct>::type  char_type;
+    typedef typename mode_of<Direct>::type       mode_type;
+    struct category 
+        : mode_type,
+          device_tag,
+          closable_tag
+          #ifndef NDNBOOST_IOSTREAMS_NO_LOCALE
+          , localizable_tag
+          #endif
+        { };
+protected:
+    explicit direct_adapter_base(const Direct& d);
+    typedef is_convertible<category, two_sequence> is_double;
+    struct pointers {
+        char_type *beg, *ptr, *end;
+    };
+    void init_input(mpl::true_);
+    void init_input(mpl::false_) { }
+    void init_output(mpl::true_);
+    void init_output(mpl::false_) { }
+    double_object<pointers, is_double>  ptrs_;
+    Direct                              d_;
+};
+
+template<typename Direct>
+class direct_adapter : private direct_adapter_base<Direct> {
+private:
+    typedef direct_adapter_base<Direct>      base_type;
+    typedef typename base_type::pointers     pointers;
+    typedef typename base_type::is_double    is_double;
+    using base_type::ptrs_;
+    using base_type::d_;
+public:
+    typedef typename base_type::char_type    char_type;
+    typedef typename base_type::category     category;
+
+        // Constructors
+
+#if !NDNBOOST_WORKAROUND(NDNBOOST_MSVC, <= 1310)
+    direct_adapter(const Direct& d) : base_type(d) { }   
+    direct_adapter(const direct_adapter& d) : base_type(d) { }
+# define NDNBOOST_PP_LOCAL_LIMITS (1, NDNBOOST_IOSTREAMS_MAX_FORWARDING_ARITY)
+#else
+    template<typename U>
+    struct is_direct
+        : mpl::or_< 
+              is_same<U, direct_adapter<Direct> >, 
+              is_same<U, Direct> 
+          >
+        { };
+    template<typename U>
+    direct_adapter(const U& u) 
+        : base_type(forward(u, is_direct<U>()))
+        { }
+# define NDNBOOST_PP_LOCAL_LIMITS (2, NDNBOOST_IOSTREAMS_MAX_FORWARDING_ARITY)
+#endif
+
+#define NDNBOOST_PP_LOCAL_MACRO(n) \
+    template<NDNBOOST_PP_ENUM_PARAMS(n, typename P)> \
+    direct_adapter(NDNBOOST_PP_ENUM_BINARY_PARAMS(n, const P, &p)) \
+        : base_type(Direct(NDNBOOST_PP_ENUM_PARAMS(n, p))) \
+        { } \
+    /**/
+#include NDNBOOST_PP_LOCAL_ITERATE()
+#undef NDNBOOST_PP_LOCAL_MACRO
+
+        // Device interface.
+
+    std::streamsize read(char_type* s, std::streamsize n);
+    std::streamsize write(const char_type* s, std::streamsize n);
+    std::streampos seek( stream_offset, NDNBOOST_IOS::seekdir,
+                         NDNBOOST_IOS::openmode = NDNBOOST_IOS::in | NDNBOOST_IOS::out );
+    void close();
+    void close(NDNBOOST_IOS::openmode which);
+#ifndef NDNBOOST_IOSTREAMS_NO_LOCALE
+    void imbue(const std::locale&);
+#endif
+
+        // Direct device access.
+
+    Direct& operator*() { return d_; }
+    Direct* operator->() { return &d_; }
+#if NDNBOOST_WORKAROUND(NDNBOOST_MSVC, <= 1310)
+private:
+    template<typename U>
+    static Direct forward(const U& u, mpl::true_) { return u; }
+    template<typename U>
+    static Direct forward(const U& u, mpl::false_) { return Direct(u); }
+#endif
+};
+
+//--------------Definition of wrap_direct and unwrap_direct-------------------//
+
+template<typename Device>
+struct wrap_direct_traits 
+    : mpl::if_<
+          is_direct<Device>,
+          direct_adapter<Device>,
+          Device
+      >
+    { };
+
+template<typename Device>
+typename wrap_direct_traits<Device>::type
+inline wrap_direct(Device dev) 
+{ 
+    typedef typename wrap_direct_traits<Device>::type type;
+    return type(dev); 
+}
+
+template<typename Device>
+inline Device& unwrap_direct(Device& d) { return d; }  
+
+template<typename Device>
+inline Device& unwrap_direct(direct_adapter<Device>& d) { return *d; }  
+
+//--------------Implementation of direct_adapter_base-------------------------//
+
+template<typename Direct>
+direct_adapter_base<Direct>::direct_adapter_base(const Direct& d) : d_(d)
+{
+    init_input(is_convertible<category, input>());
+    init_output(is_convertible<category, output>());
+}
+
+template<typename Direct>
+void direct_adapter_base<Direct>::init_input(mpl::true_) 
+{
+    std::pair<char_type*, char_type*> seq = iostreams::input_sequence(d_);
+    ptrs_.first().beg = seq.first;
+    ptrs_.first().ptr = seq.first;
+    ptrs_.first().end = seq.second;
+}
+
+template<typename Direct>
+void direct_adapter_base<Direct>::init_output(mpl::true_) 
+{
+    std::pair<char_type*, char_type*> seq = iostreams::output_sequence(d_);
+    ptrs_.second().beg = seq.first;
+    ptrs_.second().ptr = seq.first;
+    ptrs_.second().end = seq.second;
+}
+
+//--------------Implementation of direct_adapter------------------------------//
+
+template<typename Direct>
+inline std::streamsize direct_adapter<Direct>::read
+    (char_type* s, std::streamsize n)
+{
+    using namespace std;
+    pointers& get = ptrs_.first();
+    std::streamsize avail = 
+        static_cast<std::streamsize>(get.end - get.ptr);
+    std::streamsize result = (std::min)(n, avail);
+    std::copy(get.ptr, get.ptr + result, s);
+    get.ptr += result;
+    return result != 0 ? result : -1;
+}
+
+template<typename Direct>
+inline std::streamsize direct_adapter<Direct>::write
+    (const char_type* s, std::streamsize n)
+{
+    using namespace std;
+    pointers& put = ptrs_.second();
+    if (n > static_cast<std::streamsize>(put.end - put.ptr))
+        ndnboost::throw_exception(write_area_exhausted());
+    std::copy(s, s + n, put.ptr);
+    put.ptr += n;
+    return n;
+}
+
+template<typename Direct>
+inline std::streampos direct_adapter<Direct>::seek
+    ( stream_offset off, NDNBOOST_IOS::seekdir way, 
+      NDNBOOST_IOS::openmode which )
+{
+    using namespace std;
+    pointers& get = ptrs_.first();
+    pointers& put = ptrs_.second();
+    if (way == NDNBOOST_IOS::cur && get.ptr != put.ptr)
+       ndnboost::throw_exception(bad_seek());
+    ptrdiff_t next = 0;
+    if ((which & NDNBOOST_IOS::in) || !is_double::value) {
+        if (way == NDNBOOST_IOS::beg)
+            next = off; 
+        else if (way == NDNBOOST_IOS::cur)
+            next = get.ptr - get.beg + off; 
+        else
+            next = get.end - get.beg + off; 
+        if (next >= 0 && next <= get.end - get.beg)
+            get.ptr = get.beg + next;
+        else
+            ndnboost::throw_exception(bad_seek());
+    }
+    if ((which & NDNBOOST_IOS::out) && is_double::value) {
+        if (way == NDNBOOST_IOS::beg)
+            next = off; 
+        else if (way == NDNBOOST_IOS::cur)
+            next = put.ptr - put.beg + off; 
+        else
+            next = put.end - put.beg + off; 
+        if (next >= 0 && next <= put.end - put.beg)
+            put.ptr = put.beg + next;
+        else
+            ndnboost::throw_exception(bad_seek());
+    }
+    return offset_to_position(next);
+}
+
+template<typename Direct>
+void direct_adapter<Direct>::close() 
+{ 
+    NDNBOOST_STATIC_ASSERT((!is_convertible<category, two_sequence>::value));
+    detail::close_all(d_);
+}
+
+template<typename Direct>
+void direct_adapter<Direct>::close(NDNBOOST_IOS::openmode which) 
+{ 
+    NDNBOOST_STATIC_ASSERT((is_convertible<category, two_sequence>::value));
+    ndnboost::iostreams::close(d_, which);
+}
+
+#ifndef NDNBOOST_IOSTREAMS_NO_LOCALE
+    template<typename Direct>
+    void direct_adapter<Direct>::imbue(const std::locale& loc) 
+    { ndnboost::iostreams::imbue(d_, loc); }
+#endif
+
+} } } // End namespaces detail, iostreams, boost.
+
+#include <ndnboost/iostreams/detail/config/enable_warnings.hpp>
+
+#endif // #ifndef NDNBOOST_IOSTREAMS_DETAIL_DIRECT_ADAPTER_HPP_INCLUDED
diff --git a/include/ndnboost/iostreams/detail/adapter/filter_adapter.hpp b/include/ndnboost/iostreams/detail/adapter/filter_adapter.hpp
new file mode 100644
index 0000000..fec4c45
--- /dev/null
+++ b/include/ndnboost/iostreams/detail/adapter/filter_adapter.hpp
@@ -0,0 +1,69 @@
+/*
+ * Defines the class template ndnboost::iostreams::detail::filter_adapter,
+ * a convenience base class for filter adapters.
+ *
+ * File:        ndnboost/iostreams/detail/adapter/filter_adapter.hpp
+ * Date:        Mon Nov 26 14:35:48 MST 2007
+ * Copyright:   2007-2008 CodeRage, LLC
+ * Author:      Jonathan Turkanis
+ * Contact:     turkanis at coderage dot com
+ *
+ * Distributed under the Boost Software License, Version 1.0.(See accompanying 
+ * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
+ * 
+ * See http://www.boost.org/libs/iostreams for documentation.
+ */
+
+#ifndef NDNBOOST_IOSTREAMS_DETAIL_FILTER_ADAPTER_HPP_INCLUDED
+#define NDNBOOST_IOSTREAMS_DETAIL_FILTER_ADAPTER_HPP_INCLUDED
+
+#include <ndnboost/iostreams/categories.hpp>
+#include <ndnboost/iostreams/detail/call_traits.hpp>
+#include <ndnboost/iostreams/detail/ios.hpp>
+#include <ndnboost/iostreams/operations.hpp>
+#include <ndnboost/iostreams/traits.hpp>
+#include <ndnboost/static_assert.hpp>
+
+namespace ndnboost { namespace iostreams { namespace detail {
+
+template<typename T>
+class filter_adapter {
+private:
+    typedef typename detail::value_type<T>::type value_type;
+    typedef typename detail::param_type<T>::type param_type;
+public:
+    explicit filter_adapter(param_type t) : t_(t) { }
+    T& component() { return t_; }
+
+    template<typename Device>
+    void close(Device& dev) 
+    { 
+        detail::close_all(t_, dev); 
+    }
+
+    template<typename Device>
+    void close(Device& dev, NDNBOOST_IOS::openmode which) 
+    { 
+        iostreams::close(t_, dev, which); 
+    }
+
+    template<typename Device>
+    void flush(Device& dev) 
+    { 
+        return iostreams::flush(t_, dev); 
+    }
+
+    template<typename Locale> // Avoid dependency on <locale>
+    void imbue(const Locale& loc) { iostreams::imbue(t_, loc); }
+
+    std::streamsize optimal_buffer_size() const 
+    { return iostreams::optimal_buffer_size(t_); }
+public:
+    value_type t_;
+};
+
+//----------------------------------------------------------------------------//
+
+} } } // End namespaces detail, iostreams, boost.
+
+#endif // #ifndef NDNBOOST_IOSTREAMS_DETAIL_FILTER_ADAPTER_HPP_INCLUDED
diff --git a/include/ndnboost/iostreams/detail/adapter/mode_adapter.hpp b/include/ndnboost/iostreams/detail/adapter/mode_adapter.hpp
new file mode 100644
index 0000000..46d5b64
--- /dev/null
+++ b/include/ndnboost/iostreams/detail/adapter/mode_adapter.hpp
@@ -0,0 +1,123 @@
+// (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
+// (C) Copyright 2003-2007 Jonathan Turkanis
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
+
+// See http://www.boost.org/libs/iostreams for documentation.
+
+#ifndef NDNBOOST_IOSTREAMS_DETAIL_MODE_ADAPTER_HPP_INCLUDED
+#define NDNBOOST_IOSTREAMS_DETAIL_MODE_ADAPTER_HPP_INCLUDED
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+# pragma once
+#endif              
+
+// Contains the definition of the class template mode_adapter, which allows
+// a filter or device to function as if it has a different i/o mode than that
+// deduced by the metafunction mode_of.
+
+#include <ndnboost/config.hpp>                // NDNBOOST_MSVC.
+#include <ndnboost/detail/workaround.hpp>
+#include <ndnboost/iostreams/categories.hpp>
+#include <ndnboost/iostreams/detail/ios.hpp>  // openmode, seekdir, int types. 
+#include <ndnboost/iostreams/traits.hpp>
+#include <ndnboost/iostreams/operations.hpp> 
+#include <ndnboost/mpl/if.hpp> 
+
+namespace ndnboost { namespace iostreams { namespace detail {
+
+template<typename Mode, typename T>
+class mode_adapter {
+private:
+    struct empty_base { };
+public:
+    typedef typename wrapped_type<T>::type  component_type;
+    typedef typename char_type_of<T>::type  char_type;
+    struct category 
+        : Mode, 
+          device_tag,
+          mpl::if_<is_filter<T>, filter_tag, device_tag>,
+          mpl::if_<is_filter<T>, multichar_tag, empty_base>,
+          #if !NDNBOOST_WORKAROUND(NDNBOOST_MSVC, < 1300)
+              closable_tag, // VC6 can't see member close()!
+          #endif
+          localizable_tag
+        { };
+    explicit mode_adapter(const component_type& t) : t_(t) { }
+
+        // Device member functions.
+
+    std::streamsize read(char_type* s, std::streamsize n);
+    std::streamsize write(const char_type* s, std::streamsize n);
+    std::streampos seek( stream_offset off, NDNBOOST_IOS::seekdir way,
+                         NDNBOOST_IOS::openmode which = 
+                             NDNBOOST_IOS::in | NDNBOOST_IOS::out );
+#if !NDNBOOST_WORKAROUND(NDNBOOST_MSVC, < 1300)
+    void close();
+    void close(NDNBOOST_IOS::openmode which);
+#endif
+
+        // Filter member functions.
+
+    template<typename Source>
+    std::streamsize read(Source& src, char_type* s, std::streamsize n)
+    { return iostreams::read(t_, src, s, n); }
+
+    template<typename Sink>
+    std::streamsize write(Sink& snk, const char_type* s, std::streamsize n)
+    { return iostreams::write(t_, snk, s, n); }
+
+    template<typename Device>
+    std::streampos seek(Device& dev, stream_offset off, NDNBOOST_IOS::seekdir way)
+    { return iostreams::seek(t_, dev, off, way); }
+
+    template<typename Device>
+    std::streampos seek( Device& dev, stream_offset off, 
+                         NDNBOOST_IOS::seekdir way, NDNBOOST_IOS::openmode which  )
+    { return iostreams::seek(t_, dev, off, way, which); }
+
+    template<typename Device>
+    void close(Device& dev)
+    { detail::close_all(t_, dev); }
+
+    template<typename Device>
+    void close(Device& dev, NDNBOOST_IOS::openmode which)
+    { iostreams::close(t_, dev, which); }
+
+    template<typename Locale>
+    void imbue(const Locale& loc)
+    { iostreams::imbue(t_, loc); }
+private:
+    component_type t_;
+};
+                    
+//------------------Implementation of mode_adapter----------------------------//
+
+template<typename Mode, typename T>
+std::streamsize mode_adapter<Mode, T>::read
+    (char_type* s, std::streamsize n)
+{ return ndnboost::iostreams::read(t_, s, n); }
+
+template<typename Mode, typename T>
+std::streamsize mode_adapter<Mode, T>::write
+    (const char_type* s, std::streamsize n)
+{ return ndnboost::iostreams::write(t_, s, n); }
+
+template<typename Mode, typename T>
+std::streampos mode_adapter<Mode, T>::seek
+    (stream_offset off, NDNBOOST_IOS::seekdir way, NDNBOOST_IOS::openmode which)
+{ return ndnboost::iostreams::seek(t_, off, way, which); }
+
+#if !NDNBOOST_WORKAROUND(NDNBOOST_MSVC, < 1300)
+    template<typename Mode, typename T>
+    void mode_adapter<Mode, T>::close() 
+    { detail::close_all(t_); }
+
+    template<typename Mode, typename T>
+    void mode_adapter<Mode, T>::close(NDNBOOST_IOS::openmode which) 
+    { iostreams::close(t_, which); }
+#endif
+
+} } } // End namespaces detail, iostreams, boost.
+
+#endif // #ifndef NDNBOOST_IOSTREAMS_DETAIL_MODE_ADAPTER_HPP_INCLUDED //-----//
diff --git a/include/ndnboost/iostreams/detail/adapter/non_blocking_adapter.hpp b/include/ndnboost/iostreams/detail/adapter/non_blocking_adapter.hpp
new file mode 100644
index 0000000..1ba070c
--- /dev/null
+++ b/include/ndnboost/iostreams/detail/adapter/non_blocking_adapter.hpp
@@ -0,0 +1,59 @@
+// (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
+// (C) Copyright 2005-2007 Jonathan Turkanis
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
+
+// See http://www.boost.org/libs/iostreams for documentation.
+
+#ifndef NDNBOOST_IOSTREAMS_DETAIL_NON_BLOCKING_ADAPTER_HPP_INCLUDED
+#define NDNBOOST_IOSTREAMS_DETAIL_NON_BLOCKING_ADAPTER_HPP_INCLUDED
+
+#include <ndnboost/iostreams/detail/ios.hpp>  // streamsize, seekdir, openmode.
+#include <ndnboost/iostreams/read.hpp>
+#include <ndnboost/iostreams/seek.hpp>
+#include <ndnboost/iostreams/traits.hpp>
+#include <ndnboost/iostreams/write.hpp>
+
+namespace ndnboost { namespace iostreams {
+
+template<typename Device>
+class non_blocking_adapter {
+public:
+    typedef typename char_type_of<Device>::type char_type;
+    struct category
+        : mode_of<Device>::type, device_tag
+        { };
+    explicit non_blocking_adapter(Device& dev) : device_(dev) { }
+    std::streamsize read(char_type* s, std::streamsize n)
+    { 
+        std::streamsize result = 0;
+        while (result < n) {
+            std::streamsize amt = iostreams::read(device_, s, n);
+            if (amt == -1)
+                break;
+            result += amt;
+        }
+        return result != 0 ? result : -1;
+    }
+    std::streamsize write(const char_type* s, std::streamsize n)
+    { 
+        std::streamsize result = 0;
+        while (result < n) {
+            std::streamsize amt = 
+                iostreams::write(device_, s + result, n - result);
+            result += amt;
+        }
+        return result;    
+    }
+    std::streampos seek( stream_offset off, NDNBOOST_IOS::seekdir way,
+                         NDNBOOST_IOS::openmode which = 
+                             NDNBOOST_IOS::in | NDNBOOST_IOS::out )
+    { return iostreams::seek(device_, off, way, which); }
+public:
+    non_blocking_adapter& operator=(const non_blocking_adapter&);
+    Device& device_;
+};
+
+} } // End namespace iostreams.
+
+#endif // #ifndef NDNBOOST_IOSTREAMS_DETAIL_NON_BLOCKING_ADAPTER_HPP_INCLUDED
diff --git a/include/ndnboost/iostreams/detail/adapter/output_iterator_adapter.hpp b/include/ndnboost/iostreams/detail/adapter/output_iterator_adapter.hpp
new file mode 100644
index 0000000..d9b6929
--- /dev/null
+++ b/include/ndnboost/iostreams/detail/adapter/output_iterator_adapter.hpp
@@ -0,0 +1,41 @@
+// (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
+// (C) Copyright 2003-2007 Jonathan Turkanis
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
+
+// See http://www.boost.org/libs/iostreams for documentation.
+
+#ifndef NDNBOOST_IOSTREAMS_DETAIL_OUTPUT_ITERATOR_ADAPTER_HPP_INCLUDED
+#define NDNBOOST_IOSTREAMS_DETAIL_OUTPUT_ITERATOR_ADAPTER_HPP_INCLUDED
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+# pragma once
+#endif              
+
+#include <algorithm>                      // copy.
+#include <iosfwd>                         // streamsize.
+#include <ndnboost/iostreams/categories.hpp> // tags.
+#include <ndnboost/static_assert.hpp>
+#include <ndnboost/type_traits/is_convertible.hpp>
+
+namespace ndnboost { namespace iostreams { namespace detail {
+
+template<typename Mode, typename Ch, typename OutIt>
+class output_iterator_adapter {
+public:
+    NDNBOOST_STATIC_ASSERT((is_convertible<Mode, output>::value));
+    typedef Ch        char_type;
+    typedef sink_tag  category;
+    explicit output_iterator_adapter(OutIt out) : out_(out) { }
+    std::streamsize write(const char_type* s, std::streamsize n) 
+    { 
+        std::copy(s, s + n, out_); 
+        return n; 
+    }
+private:
+    OutIt out_;
+};
+
+} } } // End namespaces detail, iostreams, boost.
+
+#endif // #ifndef NDNBOOST_IOSTREAMS_DETAIL_OUTPUT_ITERATOR_ADAPTER_HPP_INCLUDED //-----//
diff --git a/include/ndnboost/iostreams/detail/adapter/range_adapter.hpp b/include/ndnboost/iostreams/detail/adapter/range_adapter.hpp
new file mode 100644
index 0000000..3789489
--- /dev/null
+++ b/include/ndnboost/iostreams/detail/adapter/range_adapter.hpp
@@ -0,0 +1,187 @@
+// (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
+// (C) Copyright 2003-2007 Jonathan Turkanis
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
+
+// See http://www.boost.org/libs/iostreams for documentation.
+
+#ifndef NDNBOOST_IOSTREAMS_DETAIL_RANGE_ADAPTER_HPP_INCLUDED
+#define NDNBOOST_IOSTREAMS_DETAIL_RANGE_ADAPTER_HPP_INCLUDED
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+# pragma once
+#endif              
+
+#include <algorithm>                             // min.
+#include <ndnboost/assert.hpp>
+#include <cstddef>                               // ptrdiff_t.
+#include <iosfwd>                                // streamsize, streamoff.
+#include <ndnboost/detail/iterator.hpp>             // ndnboost::iterator_traits.
+#include <ndnboost/iostreams/categories.hpp>
+#include <ndnboost/iostreams/detail/error.hpp>
+#include <ndnboost/iostreams/positioning.hpp>
+#include <ndnboost/mpl/if.hpp>
+#include <ndnboost/throw_exception.hpp>
+#include <ndnboost/type_traits/is_convertible.hpp>
+#include <ndnboost/utility/enable_if.hpp>
+
+// Must come last.
+#include <ndnboost/iostreams/detail/config/disable_warnings.hpp>  // MSVC.
+
+namespace ndnboost { namespace iostreams { namespace detail {
+
+// Used for simulated tag dispatch.
+template<typename Traversal> struct range_adapter_impl;
+
+//
+// Template name: range_adapter
+// Description: Device based on an instance of ndnboost::iterator_range.
+// Template parameters:
+//     Mode - A mode tag.
+//     Range - An instance of iterator_range.
+//
+template<typename Mode, typename Range>
+class range_adapter {
+private:
+    typedef typename Range::iterator                  iterator;
+    typedef ndnboost::detail::iterator_traits<iterator>  iter_traits;
+    typedef typename iter_traits::iterator_category   iter_cat;
+public:
+    typedef typename Range::value_type                char_type;
+    struct category : Mode, device_tag { };
+    typedef typename
+            mpl::if_<
+                is_convertible<
+                    iter_cat,
+                    std::random_access_iterator_tag
+                >,
+                std::random_access_iterator_tag,
+                std::forward_iterator_tag
+            >::type                                   tag;
+    typedef range_adapter_impl<tag>                   impl;
+
+    explicit range_adapter(const Range& rng);
+    range_adapter(iterator first, iterator last);
+    std::streamsize read(char_type* s, std::streamsize n);
+    std::streamsize write(const char_type* s, std::streamsize n);
+    std::streampos seek(stream_offset off, NDNBOOST_IOS::seekdir way);
+private:
+    iterator first_, cur_, last_;
+};
+
+//------------------Implementation of range_adapter---------------------------//
+
+template<typename Mode, typename Range>
+range_adapter<Mode, Range>::range_adapter(const Range& rng)
+    : first_(rng.begin()), cur_(rng.begin()), last_(rng.end()) { }
+
+template<typename Mode, typename Range>
+range_adapter<Mode, Range>::range_adapter(iterator first, iterator last)
+    : first_(first), cur_(first), last_(last) { }
+
+template<typename Mode, typename Range>
+inline std::streamsize range_adapter<Mode, Range>::read
+    (char_type* s, std::streamsize n)
+{ return impl::read(cur_, last_, s, n); }
+
+template<typename Mode, typename Range>
+inline std::streamsize range_adapter<Mode, Range>::write
+    (const char_type* s, std::streamsize n)
+{ return impl::write(cur_, last_, s, n); }
+
+
+template<typename Mode, typename Range>
+std::streampos range_adapter<Mode, Range>::seek
+    (stream_offset off, NDNBOOST_IOS::seekdir way)
+{ 
+    impl::seek(first_, cur_, last_, off, way); 
+    return offset_to_position(cur_ - first_);
+}
+
+//------------------Implementation of range_adapter_impl----------------------//
+
+template<>
+struct range_adapter_impl<std::forward_iterator_tag> {
+    template<typename Iter, typename Ch>
+    static std::streamsize read
+        (Iter& cur, Iter& last, Ch* s,std::streamsize n)
+    {
+        std::streamsize rem = n; // No. of chars remaining.
+        while (cur != last && rem-- > 0) *s++ = *cur++;
+        return n - rem != 0 ? n - rem : -1;
+    }
+
+    template<typename Iter, typename Ch>
+    static std::streamsize write
+        (Iter& cur, Iter& last, const Ch* s, std::streamsize n)
+    {
+        while (cur != last && n-- > 0) *cur++ = *s++;
+        if (cur == last && n > 0)
+            ndnboost::throw_exception(write_area_exhausted());
+        return n;
+    }
+};
+
+template<>
+struct range_adapter_impl<std::random_access_iterator_tag> {
+    template<typename Iter, typename Ch>
+    static std::streamsize read
+        (Iter& cur, Iter& last, Ch* s,std::streamsize n)
+    {
+        std::streamsize result = 
+            (std::min)(static_cast<std::streamsize>(last - cur), n);
+        if (result)
+            std::copy(cur, cur + result, s);
+        cur += result;
+        return result != 0 ? result : -1;
+    }
+
+    template<typename Iter, typename Ch>
+    static std::streamsize write
+        (Iter& cur, Iter& last, const Ch* s, std::streamsize n)
+    {
+        std::streamsize count =
+            (std::min)(static_cast<std::streamsize>(last - cur), n);
+        std::copy(s, s + count, cur);
+        cur += count;
+        if (count < n) 
+            ndnboost::throw_exception(write_area_exhausted());
+        return n;
+    }
+
+    template<typename Iter>
+    static void seek
+        ( Iter& first, Iter& cur, Iter& last, stream_offset off,
+          NDNBOOST_IOS::seekdir way )
+    {
+        using namespace std;
+        switch (way) {
+        case NDNBOOST_IOS::beg:
+            if (off > last - first || off < 0)
+                ndnboost::throw_exception(bad_seek());
+            cur = first + off;
+            break;
+        case NDNBOOST_IOS::cur:
+            {
+                std::ptrdiff_t newoff = cur - first + off;
+                if (newoff > last - first || newoff < 0)
+                    ndnboost::throw_exception(bad_seek());
+                cur += off;
+                break;
+            }
+        case NDNBOOST_IOS::end:
+            if (last - first + off < 0 || off > 0)
+                ndnboost::throw_exception(bad_seek());
+            cur = last + off;
+            break;
+        default:
+            NDNBOOST_ASSERT(0);
+        }
+    }
+};
+
+} } } // End namespaces detail, iostreams, boost.
+
+#include <ndnboost/iostreams/detail/config/enable_warnings.hpp>  // MSVC.
+
+#endif // #ifndef NDNBOOST_IOSTREAMS_DETAIL_RANGE_ADAPTER_HPP_INCLUDED //---------------//