You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "BELUGA BEHR (JIRA)" <ji...@apache.org> on 2018/03/14 15:14:30 UTC

[jira] [Created] (IO-574) Add Writes of Primitive Values To OutputStream

BELUGA BEHR created IO-574:
------------------------------

             Summary: Add Writes of Primitive Values To OutputStream
                 Key: IO-574
                 URL: https://issues.apache.org/jira/browse/IO-574
             Project: Commons IO
          Issue Type: New Feature
          Components: Utilities
    Affects Versions: 2.6
            Reporter: BELUGA BEHR


Add the capability to serialize Java primitives to OutputStream classes.

 
{code:java}
public static void writeInt(OutputStream out, int v) throws IOException {
  out.write((byte) (0xff & (v >> 24)));
  out.write((byte) (0xff & (v >> 16)));
  out.write((byte) (0xff & (v >> 8)));
  out.write((byte) (0xff & v));
}{code}
 

[https://github.com/apache/hbase/blob/c3b4f788b16ac4e0e8cfd319f495308ba4d158f5/hbase-common/src/main/java/org/apache/hadoop/hbase/io/util/StreamUtils.java#L215-L243]

[https://stackoverflow.com/questions/6374915/java-convert-int-to-byte-array-of-4-bytes]

 

Could also create a Serialize object that has an internal buffer that the bytes are written to before calling {{out.write(buf)}} once.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)