1

As the question suggest, I lneed to know the encoding of the data in the server logs.

I am getting the server logs using S3ObjectInputStream. as following:

amazonS3Client as3c;
S3ObjectInputStream is = as3c.getObject(bucketName, key).getObjectContent();
//read it for processing using buffered input stream.
BufferedReader br = new BufferedReader(new InputStreamReader(is,..unknown..));
//need character encoding(charset eg: UTF-8, UTF-16 etc.) of the data in the object 
//to pass it to InputStreamReader.

In the docs, I only see getContentEncoding() function but I do not think that it fits my purpose.

Useful references:

ObjectMetadata

AmazonS3Interface

Aman Deep Gautam
  • 8,091
  • 21
  • 74
  • 130

1 Answers1

1

Did you check the other constructor of InputStreamReader? There is a constructor that receives only the InputStream as a parameter.

http://docs.oracle.com/javase/7/docs/api/java/io/InputStreamReader.html

As far as I know, the files in S3 are saved using the encoding the writer has chosen. Anyway I would suggest you to try the UTF-8 encoding and check whether it throws a UnsupportedEncodingException.

Felipe Garcia
  • 2,263
  • 1
  • 16
  • 19
  • Yes I know that such constructor exists. But what if character encoding is different than the default encoding used by `InputStreamReader`. – Aman Deep Gautam Sep 16 '13 at 13:01
  • I just followed AWS Documentation recommendations and never had a problem. http://docs.aws.amazon.com/AmazonS3/latest/dev/RetrievingObjectUsingJava.html – Felipe Garcia Sep 16 '13 at 13:18
  • I did that as you could see the code above ut was not sure about how it would behave in that case. Anyway the documentation also does not discuss about it, so there is very less we can do. Thank you! I will still leave the question as unanswered in case anyone knows about it. – Aman Deep Gautam Sep 16 '13 at 13:24
  • As far as I can tell you can't find the encoding of a file, you can guess it. This other thread talks about it too http://stackoverflow.com/questions/3678874/get-files-encoding-in-java – Felipe Garcia Sep 16 '13 at 13:48