Submitted On 27-JAN-1998
gbishop
This is my problem EXACTLY. I have not found a
suitable replacement.
Submitted On 20-FEB-1998
DwayneS
This particular problem also makes it difficult
to use the java.sql.PreparedStatement.setAsciiStream
method as it requires an InputStream.
Submitted On 27-MAY-1998
elliotkatz
ditto.
I cannot find a workaround.
This is particularly irksome, since I was forced
to use the Properties class by the deprecation
of getenv(). Come on, guys! If it ain't broke,
don't break it!!
Submitted On 09-NOV-1998
gbishop
Because there is no properties replacement method
that takes a reader it is very annoying. Either
consistantly eliminate inputStream and
outputStream EVERYWHERE replacing all methods that
use them with reader and writer equivelents, or
provide a way to switch BOTH BACK AND FORTH.
-G
Submitted On 15-NOV-1998
ndawoud
I have the same problem...I can't go from Reader
to InputStream...
Does anyone have a workaround?
Submitted On 05-JAN-1999
dbrazziel
I have the problem of writing protocol handlers
that need to return an InputStream from getInputStream(),
but since StringBufferInputStream() is deprecated
with a suggestion to use StringReader, can't override
getInputStream to return StringReader. Please
provide a bridge.
Submitted On 27-FEB-2001
w3e4r5
Oh, I'm sorry: it's not a bug (of course), it's a
'request for enhancement' which is 3 1/2.
Submitted On 27-FEB-2001
w3e4r5
I really like the workaround
"leave the deprecated class in the code ..." (given in
4217782).
The API sais "This class does not properly convert
characters into bytes.". And I should continue to use it?
What does *that* mean?
This bug is 3 1/2 years old now. Impressive.
Submitted On 13-MAR-2001
mad.mick
seems like there are exactly 12 people in the world needing
this... come on sun, make 12 people less unhappy.
Submitted On 21-MAR-2001
paolobonanomi
** 13 ** people need a solution!
Submitted On 27-MAR-2001
cjbeer
It's a lot more than 13!
Submitted On 08-MAY-2001
cbladon
Java Eng: Come on! We're comin up on 1.4 - it's time to
take a stand!
With that said, here's a freakishly bad hack just to avoid
the deprecation warning. It still suffers from the encoding
problem:
ByteArrayInputStream stream = new
ByteArrayInputStream(string.getBytes());
Properties props = new Properties();
props.load(stream);
stream.close();
Submitted On 21-MAY-2001
mehulK
do something about this. or maybe even give load method in
Properties to accept Reader.
Submitted On 15-FEB-2002
gbishop
Who wants a laugh? You could use only boolean properties,
and use boolean's getBoolean(String name) which does not
see if a string is true or false, but instead sees if a
system property is true or false. Get Integer does the
same thing, but with integers. Hey Sun, how about a
getString that gets the string value of a system property?
Submitted On 07-NOV-2003
levmatta
This is an absurd, this bug was introduced in Nov 24, 1997.
How the hell did sun manage to avoid fixing this. The
workaround is not good enough.
Please have some shame, and fix this. It's a core functionality
and its missing since 1997, let me repeat 1997.
Submitted On 14-APR-2004
minirich
I used the StringBufferInputStream with a charset for
special encoding.
with stringReader there goes no charset and all (500)
webpages were rendered unreadable.
I changed it back to StringBufferInputStream and it
worked fine.
i fear the version of the jdk where the class is droped
Submitted On 11-JUN-2004
asokkumar
Does anyone have a work around for converting from Reader to InputStream
Submitted On 26-OCT-2004
ChristophL
OK, now we have Tiger RC and no way of converting a StringReader into an InputStream is in sight. Do we really all have to write our own adapter class ReaderInputStream, that implements InputStream and whose constructor takes an Reader, that it reads from?
- Maybe i have to wait another seven years?
Submitted On 09-NOV-2004
ocanoe
I too am astonished this did not get addressed in Tiger. I don't want a StringBufferInputStream, I just want to be able to use java.util.Properties.load( ) without funky workarounds. The ones I know:
Workarounds:
1. convert the String to its byte array, and pass that into a ByteArrayInputStream.
String s = ...;
Properties p = new Properties();
byte[] bArray = s.getBytes();
ByteArrayInputStream bais = new ByteArrayInputStream(bArray);
p.load(bais);
or
byte[] byteArray = myString.getBytes("ISO-8859-1"); // choose a charset
ByteArrayInputStream baos = new ByteArrayInputStream(byteArray);
2. When converting to a ByteArrayInputStream, this uses the platform's default character
encoding. This can potentially lose information. Another option is save to a
temporary file and read in from file. Be sure to enable delete on exit for the file so it doesn't
hang around.
3. put info in a permanent file, then read from that file with a FileInputStream. For example:
import java.io.FileInputStream;
import java.util.Properties;
public class PropertiesTest {
public static void main(String[] args) throws Exception {
// set up new properties object
// from file "myProperties.txt"
FileInputStream propFile = new FileInputStream(
"myProperties.txt");
// note this initializes the new properties object with the current set
Properties p = new Properties(System.getProperties());
p.load(propFile);
// set the system properties
System.setProperties(p);
// display new properties
System.getProperties().list(System.out);
}
}
Submitted On 24-MAY-2005
chengyukpong
try this
new InputStreamReader(new ByteArrayInputStream(Result.getBytes()),
Submitted On 05-AUG-2005
aphnwzd
thnx chengyukpong , this works fine
but are there any possible problems which could arise from using certain encoding/character table ?
this should not happen in my case, however, one never knows :)
Submitted On 27-APR-2006
bartvh
in the comment of chengyukpong, you should use Result.getBytes("ISO-8859-1"), because property files are latin-1 encoded.
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|