|
From: James W. <jw....@gm...> - 2008-08-02 12:29:47
|
The answer: Don't use Writers. I changed
FileWriter writer = new FileWriter(tempFile);
to
FileOutputStream writer = new FileOutputStream(tempFile);
I should have noticed that the file size did not match (more than double)
that of the content-length header in the response.
-James
On Thu, Jul 31, 2008 at 7:21 AM, James Wilson <jw....@gm...> wrote:
> I'm having trouble getting the photo to write to disk. I can't see in this
> code snippet what might be wrong about how I'm using the rets-client API.
> This is from a unit test that I'm using as an "exploration test" to confirm
> I'm using the rets-client api correctly against this Rapattoni RETS
> service. So you can see from the assert that the RETS service says the
> image is a jpeg. Gimp reports that the file "Not a JPEG file: starts with
> 0xef 0xbf". I've tried Photos from a couple different listings with the
> same results. Could someong please confirm that I'm using the
> GetObjectResponse correctly?
>
> -James
>
> ...snip...
> GetObjectResponse objectResponse =
> session.getObject(getObjectRequest);
>
> Assert.assertEquals("image/jpeg", objectResponse.getType());
>
> GetObjectIterator getObjectIterator = objectResponse.iterator();
> while (getObjectIterator.hasNext()) {
> SingleObjectResponse singleObjectResponse =
> getObjectIterator.next();
>
> Assert.assertEquals("image/jpeg",
> singleObjectResponse.getType());
> Assert.assertEquals(resourceEntity,
> singleObjectResponse.getContentID());
>
> InputStream inputStream =
> singleObjectResponse.getInputStream();
> BufferedInputStream bis = new BufferedInputStream(inputStream);
>
> File tempFile = File.createTempFile("rets_test_photo",
> ".jpeg");
> FileWriter writer = new FileWriter(tempFile);
>
> int b = -1;
> while ((b = bis.read()) != -1) {
> writer.write((byte) b);
> System.out.print(".");
> }
> System.out.println();
> writer.close();
> }
> ...snip...
>
|