🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.api
Article #377

Re: ntohs? htons?

#377
From: Shankar Unni
Date: Mon, 20 Oct 2003 20:19
21 lines
1848 bytes
John McGrath [TeamB] wrote:

> Can you be more specific about what you are trying to do?
> 
> When you write numeric values to streams, the standard Java classes
> always use network order, so I doubt that you really need these methods.

Perhaps he already has a binary stream from somewhere, and wants to
interpret a sequence of 2 bytes as a short.

Answer:

a. write your own routine that can take two bytes and return a short
(and does all the shifting and or'ing), or
b. use java.io.DataInputStream.

  byte[] bytes = .. some binary data ..
  DataInputStream is =
      new DataInputStream(new ByteArrayInputStream(bytes));
  ..
  // call is.read{Short,Long,UnsignedShort,...}()
Technical Details
Message-ID: <3f94434d@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.frii.net!newsfeed.frii.net!216.65.3.50.MISMATCH!news-out1.newsfeeds.com!propagator2-maxim!news-in.superfeed.net!newsfeed01.tsnz.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <3f91f19f@newsgroups.borland.com> <3f931655@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1089d0,f2a63a0b29d359c0
X-Google-Attributes: gid1089d0,public
X-Google-ArrivalTime: 2003-10-20 13:25:33 PST
Date: Mon, 20 Oct 2003 13:19:26 -0700
From: Shankar Unni <shankar@cotagesoft.com>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (Compact)
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.jbuilder.java.api
Subject: Re: ntohs? htons?
References: <3f91f19f@newsgroups.borland.com> <3f931655@newsgroups.borland.com>
In-Reply-To: <3f931655@newsgroups.borland.com>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 64.165.207.59
Message-ID: <3f94434d@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1066681165 64.165.207.59 (20 Oct 2003 13:19:25 -0700)
Lines: 22
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.frii.net!newsfeed.frii.net!216.65.3.50.MISMATCH!news-out1.newsfeeds.com!propagator2-maxim!news-in.superfeed.net!newsfeed01.tsnz.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail