I am learning GoF Java Design Patterns and I want to see some real life examples of them. Can you guys point to some good usage of these Design Patterns.(preferably in Java's core libraries).
Thank you
With reference to the following thread:
http://stackoverflow.com/questions/498636/java-app-unable-to-read-iso-8859-1-encoded-file-correctly
What is the best way to programatically determine the correct charset encoding of an inputstream/file ?
I have tried using the following:
File in = new File(args[0]);
InputStreamReader r = new InputStreamReader(new FileInputStream(in));
System.out...
In Java, I have a String and I want to encode it as a byte array (in UTF8, or some other encoding). Alternately, I have a byte array (in some known encoding) and I want to convert it into a Java String. How do I do these conversions?
I'm reading a local file using a BufferedReader wrapped around a FileReader:
BufferedReader reader = new BufferedReader(new FileReader(fileName));
// read the file
// (error handling snipped)
reader.close();
Do I need to close() the FileReader as well, or will the wrapper handle that?
I've seen code where people do something like this:
FileReader fReader = new FileReader(fileName);
Buffered...
This has probably been answered else where but how do you get the character value of an int value?
Specifically I'm reading a from a tcp stream and the readers .read() method returns an int.
How do I get a char from this?
This is a double question for you amazingly kind Stacked Overflow Wizards out there.
How do I set emacs/slime/swank to use UTF-8 when talking with Clojure, or use UTF-8 at the command-line REPL? At the moment I cannot send any non-roman characters to swank-clojure, and using the command-line REPL garbles things.
It's really easy to do regular expressions on latin text:
(re-seq #"[\w]+" "It's...
I know there used to be a way to get it with apache commons as documented here:
http://hc.apache.org/httpclient-legacy/apidocs/org/apache/commons/httpclient/HttpMethod.html
and an example here:
http://www.kodejava.org/examples/416.html
but i believe this is deprecated.
Is there any other way to make an http get request in java and get the response body as a string and not a stream?
For example I have following code
Source.fromFile(new File( path), "UTF-8").getLines()
and it throws exception
Exception in thread "main" java.nio.charset.MalformedInputException: Input length = 1
at java.nio.charset.CoderResult.throwException(CoderResult.java:260)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:319)
I don't care if some lines were not read, but how to s...
I was wondering, whether is there any need for me to close the InputStream, after I close the reader?
try {
inputStream = new java.io.FileInputStream(file);
reader = new InputStreamReader(inputStream, Charset.forName("UTF-8"));
}
catch (Exception exp) {
log.error(null, exp);
}
finally {
if (false == close(reader)) {
return null;
...
Hey Everyone , I need your help here please.
I'm working on a java application that convert data from a txt file into the database , The problem is that the file have ANSI encoding which i can't change because it comes from outside my application ,and when i write the data to the database i got some "???" inside.
My question is , how can i convert the data that i read from the file from ANSI to...
This is a "meta-question" which I came across when trying to find a better specification for another of my questions (Rendering Devanagari ligatures (Unicode) in Java Swing JComponent on Mac OS X).
What I don't quite understand as of yet is which "component" (for want of a better word) of a given system is responsible for displaying Unicode text in Java, and more specifically ligatures.
As f...
How do you read and display data from .txt files?
I have a Java application that receives data over a socket using an InputStreamReader. It reports "Cp1252" from its getEncoding method:
/* java.net. */ Socket Sock = ...;
InputStreamReader is = new InputStreamReader(Sock.getInputStream());
System.out.println("Character encoding = " + is.getEncoding());
// Prints "Character encoding = Cp1252"
That doesn't necessarily match what the system rep...
We are trying to download source of webpages, however we cannot see some specific characters -like ü,ö,ş,ç- propoerly due to character encoding. We tried the following code in order to convert encoding of the string ("text" variable):
byte[] xyz = text.getBytes();
text = new String(xyz,"windows-1254");
We observed that if encoding is utf-8, we still cannot see pages correctly. What should w...
I have a file which is encoded as iso-8859-1, and contains characters such as ô .
I am reading this file with java code, something like:
File in = new File("myfile.csv");
InputStream fr = new FileInputStream(in);
byte[] buffer = new byte[4096];
while (true) {
int byteCount = fr.read(buffer, 0, buffer.length);
if (byteCount <= 0) {
brea...
I currently use the following function to do a simple HTTP GET.
public static String download(String url) throws java.io.IOException {
java.io.InputStream s = null;
java.io.InputStreamReader r = null;
//java.io.BufferedReader b = null;
StringBuilder content = new StringBuilder();
try {
s = (java.io.InputStream)new URL(url).getContent();
r = new java.io.Inpu...
I'm trying to make a bash script that will talk to a java program that waits for my commands via bash. the java program is running as a server with a very limited GUI so I'm working on making a basic UI for it that will add functionality to it, any help on this topic would be nice.
The ways I've tried to start it currently are:
INPUTFD=258
#exec "$INPUTFD"> >(exec java -Xmx512M -Xms512M...
i need to recreate this within Java for Blackberry device:
char cPacketData[1024];
int thisPacketLength=( X_PACKET_SPACE*12 ) + ( 20*X_PACKET_SPACE );
(*(int *) (cPacketData)) =X_PACKET_START;
(*(int *) (cPacketData+X_PACKET_SPACE)) =thisPacketLength;
(*(int *) (cPacketData+X_PACKET_SPACE*2)) =X_PACKET_POSITION_DATA;
(*(int *) (cPacketData+X_PACKET_SPACE*3)) =posit...
I have issue with spanish characters in java string. I have a content in a file and when i try to transform it to java object using InputStreamReader, the output of some string is "cómo" which should be "cómo". This is happening other spanish like
á = á
é = é
í = Ã
ó = ó
ú = ú
and more..
Could you please help me to convert it appropriate output.
Thanks in advance
I am trying to read an HTML file which is encoded in EUC-KR from a URL. When I compile the code inside the IDE I get the desired output, but when I build a jar and try running the jar, the data I read is shown as question marks ("????" instead of the korean characters). I am assuming it is due to loss of encoding.
The meta of the site says the following:
<meta http-equiv="Content-Type" con...
I have a webpage that is encoded (through its header) as WIN-1255.
A Java program creates text string that are automatically embedded in the page. The problem is that the original strings are encoded in UTF-8, thus creating a Gibberish text field in the page.
Unfortunately, I can not change the page encoding - it's required by a customer propriety system.
Any ideas?
UPDATE:
The page I'm cr...