Comments (1)
The out-of-memory was caused by a getStreamBytes(InputStream is) call in the
JpegUtils.traverseJFIF method. It reads all the image-data of the image into a
byte-
array. This array can get too large and an out-of-memory can be thrown.
This byte-array is held onto for a while until the image (data and exif) is
finally
written out.
The idea of the fix is this:
Instead of lugging around a large byte-array, why not hold on to the
input-stream
instead. This will save a lot of memory. When the image-data needs to be
written
out, instead of writing a byte-array, the contents of the input-stream are
written
out instead.
Changes:
Add one more method to JPegUtils.Visitor interface:
public boolean visitSOS(int marker, byte markerBytes[], InputStream is);
It differs from the other 'visitSOS' method in that it accepts an input-stream
instead of a byte-array.
This method returns true only if the implementor of this method will close the
given
InputStream itselft. If the method returns false, the caller should close the
InputStream.
Change all implementations of JpegUtils.Visitor to implement this new method.
All but two of the implementations do absolutely nothing when this method is
called,
except returning false (the caller should close the specified InputStream).
The other two will store the InputStream in an instance-member:
ExifRewriter.analyzeJFIF implements this.
JpegRewriter.analyzeJFIF implements this.
Both these two implement this method by adding a new new JFIFPieceImageData
(markerBytes, is) to the JFIFPieces.pieces list. When the
JFIFPieceImageData.write
(OutputStream) method is called, the stored InputStream will write all its data
out
to the specified OutputStream (and close the InputStream).
Modify JpegUtils.traverseJFIF:
Remove the call to 'getStreamBytes(is)'.
Call 'doClose = !visitor.visitSOS(marker, marketBytes, is)' instead.
Only if 'doClose' is true, close the inputstream 'is' in the finally block.
Original comment by [email protected]
on 3 Oct 2009 at 4:22
from sanselanandroid.
Related Issues (8)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sanselanandroid.