fix some resource leaks

This commit is contained in:
umjammer 2019-06-09 09:43:57 +09:00
parent 7c84ea4385
commit 30a46ddfba
7 changed files with 204 additions and 57 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
/bin/
/docs/
/tmp/

103
README.md Normal file
View File

@ -0,0 +1,103 @@
<HTML>
<HEAD>
<TITLE>JBinHex</TITLE>
</HEAD>
<BODY BGCOLOR="#ffffff" LINK="#ff0000" ALINK="#ff00ff" VLINK="#990000">
<H1 ALIGN="center">JBinHex</H1>
<P><FONT SIZE=+1>
JBinHex is both a library and a command-line tool to decode files in
the Apple Macintosh BinHex 4.0 format.
</FONT></P>
<H2>Current version: 0.5</H2>
<H3>Version history:</H3>
<DL>
<DT>0.5
<DD>First released version
</DL>
<H3>Limitations in this version:</H3>
<MENU>
<LI>This version does not support segmented files such as used
on comp.binaries.mac.* newsgroups
<LI>Documentation is limited
<LI>Command line tool has does not check wether the command line
parameters are completely correct
</MENU>
<H3>Possible future features:</H3>
<UL>
<LI>Encoding of BinHex files
<LI>File-based interface that allows to switch between data and
resource fork at any moment, instead of the predetermined order
that the stream-based interface dictates
</UL>
<H3>Command-line tool</H3>
<P>The class name of the command-line tool is <CODE>org.gjt.convert.binhex.DeBinHex</CODE></P>
<P>It accepts the following command line parameters:</P>
<MENU>
<LI>Either <CODE>-u &lt;url&gt;</CODE> or <CODE>-f &lt;file&gt;</CODE>
to specify the source BinHexed file. If neither of those options
is present, <CODE>DeBinHex</CODE> reads <CODE>stdin</CODE>.
<LI><CODE>-d</CODE> to decode the data fork. It will be put in
the file with the name that came from the BinHex header.
<LI><CODE>-df &lt;filename&gt;</CODE> to decode the data fork
to the named file instead of the name that came from the BinHex
header.
<LI><CODE>-r</CODE> to decode the resource fork. It will be put
in the file with the name that came from the BinHex header, with
the extension &quot;<CODE>.resource</CODE>&quot; appended to
it.
<LI><CODE>-rf &lt;filename&gt;</CODE> to decode the resource
fork to the named file instead of the name that came from the
BinHex header.
<LI>Both <CODE>-d</CODE>/<CODE>-df</CODE> options and <CODE>-r</CODE>/<CODE>-rf</CODE>
may be present at the same time. If none of these options is
present, <CODE>DeBinHex</CODE> will decode the data fork as if
the <CODE>-d</CODE> options was specified.
<LI><CODE>-h</CODE> to only show the header of the BinHex file
on <CODE>stdout</CODE>. The decoding options are ignored.
</MENU>
<H3>Javadoc</H3>
The <A HREF="javadoc/index.html">Javadoc of the classes</A> is included in the
distribution and available online.
<H3>Download</H3>
<P><A HREF="http://www.klomp.org/packages/JBinHex.tar.gz">Download the complete package</A> including source, javadoc and jarfile with classes (36 Kb).</P>
<H3>License</H3>
<P>The package is licensed under the <B>GNU General Public License</B>,
also known as the GPL license. See file <A HREF="COPYING">COPYING</A> for
details.</P>
<H3>References</H3>
<UL>
<LI>Article written by Yves Lempereur, available as Appendix A in <A HREF="http://www.rfc.net/get2.php3/rfc1741.html">rfc1741</A>
<LI>Article titled <A HREF="http://wuarchive.wustl.edu/systems/mac/umich.edu/misc/documentation/binhex4.0specs.txt">&quot;BinHex 4.0 Definition&quot;</A> by Peter N Lewis
</UL>
<H3>Copyright</H3>
<P>All files in the package and on this site Copyright 2000 by Erwin
Bolwidt, &lt;<A HREF="mailto:ejb@klomp.org">ejb@klomp.org</A>&gt;</P>
<HR ALIGN=LEFT>
<FONT SIZE="-1">This page was last updated at april 8, 2000.</FONT>
</BODY>
</HTML>

35
pom.xml Normal file
View File

@ -0,0 +1,35 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>klomp.org</groupId>
<artifactId>jbinhex</artifactId>
<version>0.0.6</version>
<url>http://www.klomp.org/JBinHex/JBinHex.html</url>
<name>JBinHex</name>
<description>both a library and a command-line tool to decode files in the Apple Macintosh BinHex 4.0 format.
0.0.6
mavenize
fix some resource leaks</description>
<scm>
<url>https://github.com/umjammer/JBinHex</url>
</scm>
<issueManagement>
<url>https://github.com/umjammer/JBinHex/issues</url>
</issueManagement>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -19,8 +19,9 @@
package org.gjt.convert.binhex;
import java.util.*;
import java.io.*;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
/**
This class completely decodes a BinHex4 file in three parts: the header,
@ -450,8 +451,7 @@ public class BinHex4InputStream extends InputStream {
public static void main(String[] args)
{
try {
BinHex4InputStream in = new BinHex4InputStream(System.in);
try (BinHex4InputStream in = new BinHex4InputStream(System.in)) {
System.err.println(in.getHeader());
byte[] buf = new byte[1024];

View File

@ -19,9 +19,12 @@
package org.gjt.convert.binhex;
import java.util.*;
import java.io.*;
import java.net.*;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
/**
Command line program to decode binhex files from the harddisk or from
@ -144,6 +147,7 @@ public class DeBinHex
if(justHeader)
{
System.out.println(binhex.getHeader());
binhex.close();
return;
}

View File

@ -19,8 +19,10 @@
package org.gjt.convert.binhex;
import java.util.*;
import java.io.*;
import java.io.EOFException;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
/**
Converts a 7-bit encoded binhex4.0 data stream to a 8-bit encoded
@ -166,7 +168,7 @@ public class Hqx7_to_Hqx8InputStream extends FilterInputStream {
// Debug line
// System.err.print((char)streamBuffer[sbIndex]);
// Take care to return no sign-extended numbers, hence the & 0xff
return ((int)streamBuffer[sbIndex++]) & 0xff;
return (streamBuffer[sbIndex++]) & 0xff;
}
sbFilled = super.read(streamBuffer, 0, streamBuffer.length);
@ -182,7 +184,7 @@ public class Hqx7_to_Hqx8InputStream extends FilterInputStream {
// Debug line
// System.err.print((char)streamBuffer[sbIndex]);
// Take care to return no sign-extended numbers, hence the & 0xff
return ((int)streamBuffer[sbIndex++]) & 0xff;
return (streamBuffer[sbIndex++]) & 0xff;
}
private int next6bits() throws IOException
@ -299,8 +301,7 @@ public class Hqx7_to_Hqx8InputStream extends FilterInputStream {
public static void main(String[] args)
{
try {
InputStream in = new Hqx7_to_Hqx8InputStream(System.in);
try (InputStream in = new Hqx7_to_Hqx8InputStream(System.in)) {
byte[] buf = new byte[1024];
System.err.println("Starting to convert");

View File

@ -19,8 +19,10 @@
package org.gjt.convert.binhex;
import java.util.*;
import java.io.*;
import java.io.EOFException;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
/**
Decodes Run-length encoding LE from a 8-bit BinHex stream and calculates
@ -88,7 +90,7 @@ public class RLE_CRCInputStream extends FilterInputStream {
if(sbIndex < sbFilled)
// Take care to return no sign-extended numbers, hence the & 0xff
return ((int)streamBuffer[sbIndex++]) & 0xff;
return (streamBuffer[sbIndex++]) & 0xff;
sbFilled = super.read(streamBuffer, 0, streamBuffer.length);
if(sbFilled <= 0)
@ -99,7 +101,7 @@ public class RLE_CRCInputStream extends FilterInputStream {
sbIndex = 0;
// Take care to return no sign-extended numbers, hence the & 0xff
return ((int)streamBuffer[sbIndex++]) & 0xff;
return (streamBuffer[sbIndex++]) & 0xff;
}
private int nextDecodedByte() throws IOException
@ -255,8 +257,7 @@ public class RLE_CRCInputStream extends FilterInputStream {
public static void main(String[] args)
{
try {
InputStream in = new RLE_CRCInputStream(System.in);
try (InputStream in = new RLE_CRCInputStream(System.in)) {
byte[] buf = new byte[1024];
System.err.println("Starting to convert");