I have a static XML file called rules.xml in war/xml/. It is a rules file for the Apache Commons Digester. In order to be able to use the file I need to be able to open it with a Reader. How can I open the file?
try using
final String file = "xml/rules.xml";
FileReader fileReader;
try
{
fileReader = new FileReader(file);
...
}
catch(..)
edit: after some intensive usage, FileReader in GAE seems have some trouble with accentuated characters (Only visible on GAE cloud instances, local tests runs perfectly).
If someone encounters this kind of bugs, use FileInputStream instead. It worked for me.
Check this page for more informations : http://code.google.com/intl/en/appengine/kb/java.html#readfile
Cheers.
Related
This problem has stumped me for most part of my day.
BACKGROUND
I am attempting to read the Play Store reviews for my Apps via my own Google App Engine Java project.
Now I am able to get the list of all the files using Google Cloud Storage client api (java).
I can also read the meta for each of the csv files in that bucket and print it to the logs:
PROBLEM
I simply can't find a way to read the actual object and get the csv data.
My java code snippet:
BUCKET_NAME = "pubsite_prod_rev_*******";
objectFileName = "reviews/reviews_*****_***.csv"
Storage.Objects.Get obj = client.objects().get(BUCKET_NAME, objectFileName);
InputStream is = obj.executeMediaAsInputStream();
Now when I print this inputstream, it tells me its GZIPInputStream (java.util.zip.GZIPInputStream#f0be2c). Converting this inputstream to byte[] or String (desired) does not work.
And if I try to envelope it inside GZIPInputStream object using:
zis = new GZIPInputStream(is);
it throws ZipException : Not in GZIP format.
Metadata of the file:
"contentType": "text/csv; charset=utf-16le",
"contentEncoding": "gzip",
What wrong am I doing?
Sub Question: In the past I have successfully read text data from Google Cloud Storage using GcsService, but it does not seem to work with the Buckets which have the Play Store review csv files. Does anybody know if my Google App Engine project (connected to same Google developer account) can read these Buckets?
Solved it using executeMedia() and parseAsString
HttpResponse response = obj.executeMedia();
response.parseAsString(); //works!!
I'm developing a Google App Engine application in eclipse indigo. I'm trying to upload a word file in database using HTML file input, but it seems that my servlet version is below 3.0 and I can't use methods like getPart(). Is there any other way to this?
Did you try with the blobstoreService?
Map<String, List<BlobKey>> blobs = blobstoreService.getUploads(req);
To see more about it you can check here: https://cloud.google.com/appengine/docs/java/blobstore/
I have uploaded Excel file into GCS . Using Apache POI library from local excel file
i am able to read data.
I am not getting avaliable file readers and methods to Read data from GCS.
please suggest me excel file reading methods from GCS.
thanks in advance.
Since this is still unanswered I'll expand upon the previous comment : The GCS Client Library[1] will give you an InputStream which you can use to read the data from GCS:
GcsFilename fileName = new GcsFilename("bucket", "test.xlsx");
GcsInputChannel readChannel = gcsService.openPrefetchingReadChannel(fileName, 0, BUFFER_SIZE);
InputStream inputStream = Channels.newInputStream(readChannel);
XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
XSSFSheet sheet = workbook.getSheetAt(0);
Iterator<Row> rowIterator = sheet.iterator();
while (rowIterator.hasNext()) {
// Do stuff...
}
Note that if you want to use POI on the App Engine runtime itself you will need to use a nightly build of POI or build from source yourself, otherwise you will run into the issue 'com.sun.org.apache.xerces.internal.util.SecurityManager is a restricted class'[2].
[1] https://cloud.google.com/appengine/docs/java/googlecloudstorageclient/
[2] Google App Engine and Apache Poi loading templates
What I'm trying to do is simple. Load am XML file using ElementTree so I can traverse it.
Here's the code:
_uri = '/news.xml'
self.root = ElementTree.parse(_uri).getroot()
And, the error:
file not accessible: '/news.xml'
From what I can tell, the parser can't find the document. Is there something I need to configure so python can see my site's files?
This is probably similar to:
Read a file on App Engine with Python?
I.e. files that are marked as static are not accessible, but you can also serve it as an application resource file.
I want to access a file in computer(c:\test.bin) and to read it as byte array .Is it possible in Windows phone .
Thanks and Regards
vaysage
You cannot access a file via any standard file I/O apis.
You can run a web server on that computer, make the file available via http and include the appropriate client access policy file in the web site. You can then download the file via WebClient using OpenReadAsync.
If you would like to upload something as a project asset, then you should force it to be a "content" from the properties panel and then access it using :
Uri uriMyFile = new Uri("test.bin",UriKind.relative);
StreamReader sr = new StreamReader((Application.GetResourcesStream(
uriMyFile)).Stream);