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:
DRC
2015-07-07 16:39:03 +00:00
parent 65c5ec2f0f
commit 1a4778f8f0
9 changed files with 57 additions and 20 deletions

View File

@@ -11,6 +11,10 @@ use of AltiVec instructions.
[2] Added a new libjpeg API function (jpeg_skip_scanlines()) that can be used [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. 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 1.4.1
===== =====

View File

@@ -90,10 +90,15 @@
<div class="description"> <div class="description">
<ul class="blockList"> <ul class="blockList">
<li class="blockList"> <li class="blockList">
<dl>
<dt>All Implemented Interfaces:</dt>
<dd>java.io.Closeable, java.lang.AutoCloseable</dd>
</dl>
<hr> <hr>
<br> <br>
<pre>public class <span class="strong">TJCompressor</span> <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> <div class="block">TurboJPEG compressor</div>
</li> </li>
</ul> </ul>
@@ -828,10 +833,15 @@ public&nbsp;byte[]&nbsp;encodeYUV(java.awt.image.BufferedImage&nbsp;srcImage,
<li class="blockList"> <li class="blockList">
<h4>close</h4> <h4>close</h4>
<pre>public&nbsp;void&nbsp;close() <pre>public&nbsp;void&nbsp;close()
throws java.lang.Exception</pre> throws java.io.IOException</pre>
<div class="block">Free the native structures associated with this compressor instance.</div> <div class="block">Free the native structures associated with this compressor instance.</div>
<dl><dt><span class="strong">Throws:</span></dt> <dl>
<dd><code>java.lang.Exception</code></dd></dl> <dt><strong>Specified by:</strong></dt>
<dd><code>close</code>&nbsp;in interface&nbsp;<code>java.io.Closeable</code></dd>
<dt><strong>Specified by:</strong></dt>
<dd><code>close</code>&nbsp;in interface&nbsp;<code>java.lang.AutoCloseable</code></dd>
<dt><span class="strong">Throws:</span></dt>
<dd><code>java.io.IOException</code></dd></dl>
</li> </li>
</ul> </ul>
<a name="finalize()"> <a name="finalize()">

View File

@@ -91,13 +91,18 @@
<ul class="blockList"> <ul class="blockList">
<li class="blockList"> <li class="blockList">
<dl> <dl>
<dt>All Implemented Interfaces:</dt>
<dd>java.io.Closeable, java.lang.AutoCloseable</dd>
</dl>
<dl>
<dt>Direct Known Subclasses:</dt> <dt>Direct Known Subclasses:</dt>
<dd><a href="../../../org/libjpegturbo/turbojpeg/TJTransformer.html" title="class in org.libjpegturbo.turbojpeg">TJTransformer</a></dd> <dd><a href="../../../org/libjpegturbo/turbojpeg/TJTransformer.html" title="class in org.libjpegturbo.turbojpeg">TJTransformer</a></dd>
</dl> </dl>
<hr> <hr>
<br> <br>
<pre>public class <span class="strong">TJDecompressor</span> <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> <div class="block">TurboJPEG decompressor</div>
</li> </li>
</ul> </ul>
@@ -1162,10 +1167,15 @@ public&nbsp;byte[]&nbsp;decompressToYUV(int&nbsp;flags)
<li class="blockList"> <li class="blockList">
<h4>close</h4> <h4>close</h4>
<pre>public&nbsp;void&nbsp;close() <pre>public&nbsp;void&nbsp;close()
throws java.lang.Exception</pre> throws java.io.IOException</pre>
<div class="block">Free the native structures associated with this decompressor instance.</div> <div class="block">Free the native structures associated with this decompressor instance.</div>
<dl><dt><span class="strong">Throws:</span></dt> <dl>
<dd><code>java.lang.Exception</code></dd></dl> <dt><strong>Specified by:</strong></dt>
<dd><code>close</code>&nbsp;in interface&nbsp;<code>java.io.Closeable</code></dd>
<dt><strong>Specified by:</strong></dt>
<dd><code>close</code>&nbsp;in interface&nbsp;<code>java.lang.AutoCloseable</code></dd>
<dt><span class="strong">Throws:</span></dt>
<dd><code>java.io.IOException</code></dd></dl>
</li> </li>
</ul> </ul>
<a name="finalize()"> <a name="finalize()">

View File

@@ -95,6 +95,10 @@
<div class="description"> <div class="description">
<ul class="blockList"> <ul class="blockList">
<li class="blockList"> <li class="blockList">
<dl>
<dt>All Implemented Interfaces:</dt>
<dd>java.io.Closeable, java.lang.AutoCloseable</dd>
</dl>
<hr> <hr>
<br> <br>
<pre>public class <span class="strong">TJTransformer</span> <pre>public class <span class="strong">TJTransformer</span>

View File

@@ -80,8 +80,8 @@
</ul> </ul>
</li> </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/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/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> <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> <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> <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> </ul>

View File

@@ -84,8 +84,8 @@
</ul> </ul>
</li> </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/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/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> <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> <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> <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> </ul>

View File

@@ -30,11 +30,12 @@ package org.libjpegturbo.turbojpeg;
import java.awt.image.*; import java.awt.image.*;
import java.nio.*; import java.nio.*;
import java.io.*;
/** /**
* TurboJPEG compressor * TurboJPEG compressor
*/ */
public class TJCompressor { public class TJCompressor implements Closeable {
private static final String NO_ASSOC_ERROR = private static final String NO_ASSOC_ERROR =
"No source image is associated with this instance"; "No source image is associated with this instance";
@@ -567,7 +568,7 @@ public class TJCompressor {
/** /**
* Free the native structures associated with this compressor instance. * Free the native structures associated with this compressor instance.
*/ */
public void close() throws Exception { public void close() throws IOException {
if (handle != 0) if (handle != 0)
destroy(); destroy();
} }
@@ -583,7 +584,7 @@ public class TJCompressor {
private native void init() throws Exception; private native void init() throws Exception;
private native void destroy() throws Exception; private native void destroy() throws IOException;
// JPEG size in bytes is returned // JPEG size in bytes is returned
private native int compress(byte[] srcBuf, int width, int pitch, private native int compress(byte[] srcBuf, int width, int pitch,

View File

@@ -30,11 +30,12 @@ package org.libjpegturbo.turbojpeg;
import java.awt.image.*; import java.awt.image.*;
import java.nio.*; import java.nio.*;
import java.io.*;
/** /**
* TurboJPEG decompressor * TurboJPEG decompressor
*/ */
public class TJDecompressor { public class TJDecompressor implements Closeable {
private static final String NO_ASSOC_ERROR = private static final String NO_ASSOC_ERROR =
"No JPEG image is associated with this instance"; "No JPEG image is associated with this instance";
@@ -833,7 +834,7 @@ public class TJDecompressor {
/** /**
* Free the native structures associated with this decompressor instance. * Free the native structures associated with this decompressor instance.
*/ */
public void close() throws Exception { public void close() throws IOException {
if (handle != 0) if (handle != 0)
destroy(); destroy();
} }
@@ -849,7 +850,7 @@ public class TJDecompressor {
private native void init() throws Exception; 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) private native void decompressHeader(byte[] srcBuf, int size)
throws Exception; throws Exception;

View File

@@ -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 * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@@ -46,6 +46,13 @@
goto bailout; \ 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)) { \ #define bailif0(f) {if(!(f)) { \
char temps[80]; \ char temps[80]; \
snprintf(temps, 80, "Unexpected NULL condition in line %d", __LINE__); \ snprintf(temps, 80, "Unexpected NULL condition in line %d", __LINE__); \
@@ -531,7 +538,7 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_destroy
gethandle(); gethandle();
if(tjDestroy(handle)==-1) _throw(tjGetErrorStr()); if(tjDestroy(handle)==-1) _throwio(tjGetErrorStr());
(*env)->SetLongField(env, obj, _fid, 0); (*env)->SetLongField(env, obj, _fid, 0);
bailout: bailout: