Re-port StringIO and methods required for it.

This incorporates missing flags, string modification, and encoding
logic into StringIO by doing a line-by-line behavior port from
MRI.

Fixes #1204.
Fixes #1242.
Merge remote-tracking branch 'github/jruby-1_7' into jruby-1_7