Allow TJCompressor and TJDecompressor to be used with a try-with-resources statement in Java 7 and later.
git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/trunk@1594 632fc199-4ca6-4c93-a231-07263d6284db
This commit is contained in:
@@ -11,6 +11,10 @@ use of AltiVec instructions.
|
||||
[2] Added a new libjpeg API function (jpeg_skip_scanlines()) that can be used
|
||||
to partially decode a JPEG image. See libjpeg.txt for more details.
|
||||
|
||||
[3] The TJCompressor and TJDecompressor classes in the TurboJPEG Java API now
|
||||
implement the Closeable interface, so those classes can be used with a
|
||||
try-with-resources statement.
|
||||
|
||||
|
||||
1.4.1
|
||||
=====
|
||||
|
||||
@@ -90,10 +90,15 @@
|
||||
<div class="description">
|
||||
<ul class="blockList">
|
||||
<li class="blockList">
|
||||
<dl>
|
||||
<dt>All Implemented Interfaces:</dt>
|
||||
<dd>java.io.Closeable, java.lang.AutoCloseable</dd>
|
||||
</dl>
|
||||
<hr>
|
||||
<br>
|
||||
<pre>public class <span class="strong">TJCompressor</span>
|
||||
extends java.lang.Object</pre>
|
||||
extends java.lang.Object
|
||||
implements java.io.Closeable</pre>
|
||||
<div class="block">TurboJPEG compressor</div>
|
||||
</li>
|
||||
</ul>
|
||||
@@ -828,10 +833,15 @@ public byte[] encodeYUV(java.awt.image.BufferedImage srcImage,
|
||||
<li class="blockList">
|
||||
<h4>close</h4>
|
||||
<pre>public void close()
|
||||
throws java.lang.Exception</pre>
|
||||
throws java.io.IOException</pre>
|
||||
<div class="block">Free the native structures associated with this compressor instance.</div>
|
||||
<dl><dt><span class="strong">Throws:</span></dt>
|
||||
<dd><code>java.lang.Exception</code></dd></dl>
|
||||
<dl>
|
||||
<dt><strong>Specified by:</strong></dt>
|
||||
<dd><code>close</code> in interface <code>java.io.Closeable</code></dd>
|
||||
<dt><strong>Specified by:</strong></dt>
|
||||
<dd><code>close</code> in interface <code>java.lang.AutoCloseable</code></dd>
|
||||
<dt><span class="strong">Throws:</span></dt>
|
||||
<dd><code>java.io.IOException</code></dd></dl>
|
||||
</li>
|
||||
</ul>
|
||||
<a name="finalize()">
|
||||
|
||||
@@ -91,13 +91,18 @@
|
||||
<ul class="blockList">
|
||||
<li class="blockList">
|
||||
<dl>
|
||||
<dt>All Implemented Interfaces:</dt>
|
||||
<dd>java.io.Closeable, java.lang.AutoCloseable</dd>
|
||||
</dl>
|
||||
<dl>
|
||||
<dt>Direct Known Subclasses:</dt>
|
||||
<dd><a href="../../../org/libjpegturbo/turbojpeg/TJTransformer.html" title="class in org.libjpegturbo.turbojpeg">TJTransformer</a></dd>
|
||||
</dl>
|
||||
<hr>
|
||||
<br>
|
||||
<pre>public class <span class="strong">TJDecompressor</span>
|
||||
extends java.lang.Object</pre>
|
||||
extends java.lang.Object
|
||||
implements java.io.Closeable</pre>
|
||||
<div class="block">TurboJPEG decompressor</div>
|
||||
</li>
|
||||
</ul>
|
||||
@@ -1162,10 +1167,15 @@ public byte[] decompressToYUV(int flags)
|
||||
<li class="blockList">
|
||||
<h4>close</h4>
|
||||
<pre>public void close()
|
||||
throws java.lang.Exception</pre>
|
||||
throws java.io.IOException</pre>
|
||||
<div class="block">Free the native structures associated with this decompressor instance.</div>
|
||||
<dl><dt><span class="strong">Throws:</span></dt>
|
||||
<dd><code>java.lang.Exception</code></dd></dl>
|
||||
<dl>
|
||||
<dt><strong>Specified by:</strong></dt>
|
||||
<dd><code>close</code> in interface <code>java.io.Closeable</code></dd>
|
||||
<dt><strong>Specified by:</strong></dt>
|
||||
<dd><code>close</code> in interface <code>java.lang.AutoCloseable</code></dd>
|
||||
<dt><span class="strong">Throws:</span></dt>
|
||||
<dd><code>java.io.IOException</code></dd></dl>
|
||||
</li>
|
||||
</ul>
|
||||
<a name="finalize()">
|
||||
|
||||
@@ -95,6 +95,10 @@
|
||||
<div class="description">
|
||||
<ul class="blockList">
|
||||
<li class="blockList">
|
||||
<dl>
|
||||
<dt>All Implemented Interfaces:</dt>
|
||||
<dd>java.io.Closeable, java.lang.AutoCloseable</dd>
|
||||
</dl>
|
||||
<hr>
|
||||
<br>
|
||||
<pre>public class <span class="strong">TJTransformer</span>
|
||||
|
||||
@@ -80,8 +80,8 @@
|
||||
</ul>
|
||||
</li>
|
||||
<li type="circle">org.libjpegturbo.turbojpeg.<a href="../../../org/libjpegturbo/turbojpeg/TJ.html" title="class in org.libjpegturbo.turbojpeg"><span class="strong">TJ</span></a></li>
|
||||
<li type="circle">org.libjpegturbo.turbojpeg.<a href="../../../org/libjpegturbo/turbojpeg/TJCompressor.html" title="class in org.libjpegturbo.turbojpeg"><span class="strong">TJCompressor</span></a></li>
|
||||
<li type="circle">org.libjpegturbo.turbojpeg.<a href="../../../org/libjpegturbo/turbojpeg/TJDecompressor.html" title="class in org.libjpegturbo.turbojpeg"><span class="strong">TJDecompressor</span></a>
|
||||
<li type="circle">org.libjpegturbo.turbojpeg.<a href="../../../org/libjpegturbo/turbojpeg/TJCompressor.html" title="class in org.libjpegturbo.turbojpeg"><span class="strong">TJCompressor</span></a> (implements java.io.Closeable)</li>
|
||||
<li type="circle">org.libjpegturbo.turbojpeg.<a href="../../../org/libjpegturbo/turbojpeg/TJDecompressor.html" title="class in org.libjpegturbo.turbojpeg"><span class="strong">TJDecompressor</span></a> (implements java.io.Closeable)
|
||||
<ul>
|
||||
<li type="circle">org.libjpegturbo.turbojpeg.<a href="../../../org/libjpegturbo/turbojpeg/TJTransformer.html" title="class in org.libjpegturbo.turbojpeg"><span class="strong">TJTransformer</span></a></li>
|
||||
</ul>
|
||||
|
||||
@@ -84,8 +84,8 @@
|
||||
</ul>
|
||||
</li>
|
||||
<li type="circle">org.libjpegturbo.turbojpeg.<a href="org/libjpegturbo/turbojpeg/TJ.html" title="class in org.libjpegturbo.turbojpeg"><span class="strong">TJ</span></a></li>
|
||||
<li type="circle">org.libjpegturbo.turbojpeg.<a href="org/libjpegturbo/turbojpeg/TJCompressor.html" title="class in org.libjpegturbo.turbojpeg"><span class="strong">TJCompressor</span></a></li>
|
||||
<li type="circle">org.libjpegturbo.turbojpeg.<a href="org/libjpegturbo/turbojpeg/TJDecompressor.html" title="class in org.libjpegturbo.turbojpeg"><span class="strong">TJDecompressor</span></a>
|
||||
<li type="circle">org.libjpegturbo.turbojpeg.<a href="org/libjpegturbo/turbojpeg/TJCompressor.html" title="class in org.libjpegturbo.turbojpeg"><span class="strong">TJCompressor</span></a> (implements java.io.Closeable)</li>
|
||||
<li type="circle">org.libjpegturbo.turbojpeg.<a href="org/libjpegturbo/turbojpeg/TJDecompressor.html" title="class in org.libjpegturbo.turbojpeg"><span class="strong">TJDecompressor</span></a> (implements java.io.Closeable)
|
||||
<ul>
|
||||
<li type="circle">org.libjpegturbo.turbojpeg.<a href="org/libjpegturbo/turbojpeg/TJTransformer.html" title="class in org.libjpegturbo.turbojpeg"><span class="strong">TJTransformer</span></a></li>
|
||||
</ul>
|
||||
|
||||
@@ -30,11 +30,12 @@ package org.libjpegturbo.turbojpeg;
|
||||
|
||||
import java.awt.image.*;
|
||||
import java.nio.*;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* TurboJPEG compressor
|
||||
*/
|
||||
public class TJCompressor {
|
||||
public class TJCompressor implements Closeable {
|
||||
|
||||
private static final String NO_ASSOC_ERROR =
|
||||
"No source image is associated with this instance";
|
||||
@@ -567,7 +568,7 @@ public class TJCompressor {
|
||||
/**
|
||||
* Free the native structures associated with this compressor instance.
|
||||
*/
|
||||
public void close() throws Exception {
|
||||
public void close() throws IOException {
|
||||
if (handle != 0)
|
||||
destroy();
|
||||
}
|
||||
@@ -583,7 +584,7 @@ public class TJCompressor {
|
||||
|
||||
private native void init() throws Exception;
|
||||
|
||||
private native void destroy() throws Exception;
|
||||
private native void destroy() throws IOException;
|
||||
|
||||
// JPEG size in bytes is returned
|
||||
private native int compress(byte[] srcBuf, int width, int pitch,
|
||||
|
||||
@@ -30,11 +30,12 @@ package org.libjpegturbo.turbojpeg;
|
||||
|
||||
import java.awt.image.*;
|
||||
import java.nio.*;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* TurboJPEG decompressor
|
||||
*/
|
||||
public class TJDecompressor {
|
||||
public class TJDecompressor implements Closeable {
|
||||
|
||||
private static final String NO_ASSOC_ERROR =
|
||||
"No JPEG image is associated with this instance";
|
||||
@@ -833,7 +834,7 @@ public class TJDecompressor {
|
||||
/**
|
||||
* Free the native structures associated with this decompressor instance.
|
||||
*/
|
||||
public void close() throws Exception {
|
||||
public void close() throws IOException {
|
||||
if (handle != 0)
|
||||
destroy();
|
||||
}
|
||||
@@ -849,7 +850,7 @@ public class TJDecompressor {
|
||||
|
||||
private native void init() throws Exception;
|
||||
|
||||
private native void destroy() throws Exception;
|
||||
private native void destroy() throws IOException;
|
||||
|
||||
private native void decompressHeader(byte[] srcBuf, int size)
|
||||
throws Exception;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C)2011-2014 D. R. Commander. All Rights Reserved.
|
||||
* Copyright (C)2011-2015 D. R. Commander. All Rights Reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
@@ -46,6 +46,13 @@
|
||||
goto bailout; \
|
||||
}
|
||||
|
||||
#define _throwio(msg) { \
|
||||
jclass _exccls=(*env)->FindClass(env, "java/io/IOException"); \
|
||||
if(!_exccls) goto bailout; \
|
||||
(*env)->ThrowNew(env, _exccls, msg); \
|
||||
goto bailout; \
|
||||
}
|
||||
|
||||
#define bailif0(f) {if(!(f)) { \
|
||||
char temps[80]; \
|
||||
snprintf(temps, 80, "Unexpected NULL condition in line %d", __LINE__); \
|
||||
@@ -531,7 +538,7 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_destroy
|
||||
|
||||
gethandle();
|
||||
|
||||
if(tjDestroy(handle)==-1) _throw(tjGetErrorStr());
|
||||
if(tjDestroy(handle)==-1) _throwio(tjGetErrorStr());
|
||||
(*env)->SetLongField(env, obj, _fid, 0);
|
||||
|
||||
bailout:
|
||||
|
||||
Reference in New Issue
Block a user