🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Newbie Question

#3349
From: Andrew Bennett
Date: Tue, 27 Jan 1998 00:00
49 lines
2342 bytes


David Gordon wrote:

> I am coding a program that reads a simple text file, reformats it and then
> inserts it into a database.  Shown below is a code fragment from the
> program:
>
> try {
>           while (ZipCodeFile.read(StateAbbrv) != -1) {
>             String s = new String(StateAbbrv,0);
>             ZipCodeFile.read();
>             ZipCodeFile.read(ZipCodeRangeLow);
>             ZipStringLow = new String(ZipCodeRangeLow,0);
>             Low = Low.decode(ZipStringLow);
>             ZipCodeLow = Low.intValue() * 100;
> ....
>
> I have two questions.  First, the documentation says that the String
> constructor I am using is "deprecated" and will not be supported in future
> releases.  How can I recode this line to convert a byte array into a string?
> Second, will I run into any problems allocating a new String variable every
> time the loop encounters this line?

1.1 added some new constructors.  I'll leave it to you to decide which you like:

  public String(byte[] bytes, int offset, int length, String enc) throws
UnsupportedEncodingException;
  public String(byte[] bytes, String enc) throws UnsupportedEncodingException;
  public String(byte[] bytes, int offset, int length);
  public String(byte[] bytes);


As for creation of a new object and a cast, you might find it faster to declare
a
object prior to the while.. statement, and clone it inside.  I recall seeing an
article
on JavaSoft's web site that indicated casting and object creation are
bottlenecks
in terms of cpu cycles currently.


Andrew
--
  Andrew Bennett            ->  abennett@borland.com
  JBuilder info             ->  http://www.borland.com/jbuilder/
  JBuilder newsgroups info  ->  http://www.borland.com/newsgroups/
**** Please don't post a reply AND send email.  Do one.  I'll see it. ****
Technical Details
Message-ID: <34CE30C6.1C35575B@borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <6ajai1$rk35@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1089d0,af44a14a5390967a
X-Google-Attributes: gid1089d0,public
From: Andrew Bennett <abennett@borland.com>
Subject: Re: Newbie Question
Date: 1998/01/27
Message-ID: <34CE30C6.1C35575B@borland.com>
X-Deja-AN: 319741075
Content-Transfer-Encoding: 7bit
References: <6ajai1$rk35@forums.borland.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Organization: None
Newsgroups: borland.public.jbuilder.java.api