[ 
https://issues.apache.org/jira/browse/IO-574?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17801470#comment-17801470
 ] 

Elliotte Rusty Harold commented on IO-574:
------------------------------------------

This is what DataOutputStream is for, as well as Guava's ints.toByteArray, 
parts of ByteBuffer, and probably other things I haven't found. Adding another 
way to do this is of trivial, if any, benefit and is extra code to maintain. 
Maybe there's an argument for a general Int.toByteArray method in commons lang 
but I don't think it belongs here. I suggest closing this one as "Won't Do"

> 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: David Mollitor
>            Priority: Major
>
> 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
(v8.20.10#820010)

Reply via email to