Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import com.sun.imageio.plugins.common.SubImageInputStream;
import java.io.ByteArrayOutputStream;
import sun.awt.image.ByteInterleavedRaster;
import sun.misc.IOUtils;

class PNGImageDataEnumeration implements Enumeration<InputStream> {

Expand Down Expand Up @@ -620,18 +621,9 @@ private void parse_tRNS_chunk(int chunkLength) throws IOException {

private static byte[] inflate(byte[] b) throws IOException {
InputStream bais = new ByteArrayInputStream(b);
InputStream iis = new InflaterInputStream(bais);
ByteArrayOutputStream baos = new ByteArrayOutputStream();

int c;
try {
while ((c = iis.read()) != -1) {
baos.write(c);
}
} finally {
iis.close();
try (InputStream iis = new InflaterInputStream(bais)) {
return IOUtils.readAllBytes(iis);
}
return baos.toByteArray();
}

private void parse_zTXt_chunk(int chunkLength) throws IOException {
Expand Down
14 changes: 8 additions & 6 deletions jdk/src/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java
Original file line number Diff line number Diff line change
Expand Up @@ -531,14 +531,16 @@ public Object run() {
URL url = new URL(new File(userHome).toURI().toURL(),
".gconf/apps/metacity/general/%25gconf.xml");
// Pending: verify character encoding spec for gconf
Reader reader = new InputStreamReader(url.openStream(), "ISO-8859-1");
char[] buf = new char[1024];
StringBuffer strBuf = new StringBuffer();
int n;
while ((n = reader.read(buf)) >= 0) {
strBuf.append(buf, 0, n);
try (InputStream in = url.openStream();
Reader reader = new InputStreamReader(in, "ISO-8859-1"))
{
char[] buf = new char[1024];
int n;
while ((n = reader.read(buf)) >= 0) {
strBuf.append(buf, 0, n);
}
}
reader.close();
String str = strBuf.toString();
if (str != null) {
String strLowerCase = str.toLowerCase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@ public final class AudioFileSoundbankReader extends SoundbankReader {

public Soundbank getSoundbank(URL url)
throws InvalidMidiDataException, IOException {
try {
AudioInputStream ais = AudioSystem.getAudioInputStream(url);
try (AudioInputStream ais = AudioSystem.getAudioInputStream(url)) {
Soundbank sbk = getSoundbank(ais);
ais.close();
return sbk;
} catch (UnsupportedAudioFileException e) {
return null;
Expand Down
24 changes: 11 additions & 13 deletions jdk/src/share/classes/com/sun/media/sound/DLSSoundbank.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,22 +186,16 @@ public DLSSoundbank() {
}

public DLSSoundbank(URL url) throws IOException {
InputStream is = url.openStream();
try {
try (InputStream is = url.openStream()) {
readSoundbank(is);
} finally {
is.close();
}
}

public DLSSoundbank(File file) throws IOException {
largeFormat = true;
sampleFile = file;
InputStream is = new FileInputStream(file);
try {
try (InputStream is = new FileInputStream(file)) {
readSoundbank(is);
} finally {
is.close();
}
}

Expand Down Expand Up @@ -870,15 +864,21 @@ private void readWaveInfoChunk(DLSSample dlssample, RIFFReader riff)
}

public void save(String name) throws IOException {
writeSoundbank(new RIFFWriter(name, "DLS "));
try (RIFFWriter writer = new RIFFWriter(name, "DLS ")) {
writeSoundbank(writer);
}
}

public void save(File file) throws IOException {
writeSoundbank(new RIFFWriter(file, "DLS "));
try (RIFFWriter writer = new RIFFWriter(file, "DLS ")) {
writeSoundbank(writer);
}
}

public void save(OutputStream out) throws IOException {
writeSoundbank(new RIFFWriter(out, "DLS "));
try (RIFFWriter writer = new RIFFWriter(out, "DLS ")) {
writeSoundbank(writer);
}
}

private void writeSoundbank(RIFFWriter writer) throws IOException {
Expand Down Expand Up @@ -918,8 +918,6 @@ private void writeSoundbank(RIFFWriter writer) throws IOException {
writer.seek(bak);

writeInfo(writer.writeList("INFO"), info);

writer.close();
}

private void writeSample(RIFFWriter writer, DLSSample sample)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ public final class JARSoundbankReader extends SoundbankReader {
private static boolean isZIP(URL url) {
boolean ok = false;
try {
InputStream stream = url.openStream();
try {
try (InputStream stream = url.openStream()) {
byte[] buff = new byte[4];
ok = stream.read(buff) == 4;
if (ok) {
Expand All @@ -71,8 +70,6 @@ private static boolean isZIP(URL url) {
&& buff[2] == 0x03
&& buff[3] == 0x04);
}
} finally {
stream.close();
}
} catch (IOException e) {
}
Expand Down
12 changes: 7 additions & 5 deletions jdk/src/share/classes/com/sun/media/sound/ModelByteBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,13 @@ public void load() throws IOException {
"No file associated with this ByteBuffer!");
}

DataInputStream is = new DataInputStream(getInputStream());
buffer = new byte[(int) capacity()];
offset = 0;
is.readFully(buffer);
is.close();
try (InputStream is = getInputStream();
DataInputStream dis = new DataInputStream(is))
{
buffer = new byte[(int) capacity()];
offset = 0;
dis.readFully(buffer);
}

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -172,18 +172,12 @@ public AudioFormat getFormat() {
if (format == null) {
if (buffer == null)
return null;
InputStream is = buffer.getInputStream();
AudioFormat format = null;
try {
try (InputStream is = buffer.getInputStream()) {
format = AudioSystem.getAudioFileFormat(is).getFormat();
} catch (Exception e) {
//e.printStackTrace();
}
try {
is.close();
} catch (IOException e) {
//e.printStackTrace();
}
return format;
}
return format;
Expand Down
24 changes: 11 additions & 13 deletions jdk/src/share/classes/com/sun/media/sound/SF2Soundbank.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,16 @@ public SF2Soundbank() {
}

public SF2Soundbank(URL url) throws IOException {

InputStream is = url.openStream();
try {
try (InputStream is = url.openStream()) {
readSoundbank(is);
} finally {
is.close();
}
}

public SF2Soundbank(File file) throws IOException {
largeFormat = true;
sampleFile = file;
InputStream is = new FileInputStream(file);
try {
try (InputStream is = new FileInputStream(file)) {
readSoundbank(is);
} finally {
is.close();
}
}

Expand Down Expand Up @@ -522,22 +515,27 @@ private void readPdtaChunk(RIFFReader riff) throws IOException {
}

public void save(String name) throws IOException {
writeSoundbank(new RIFFWriter(name, "sfbk"));
try (RIFFWriter writer = new RIFFWriter(name, "sfbk")) {
writeSoundbank(writer);
}
}

public void save(File file) throws IOException {
writeSoundbank(new RIFFWriter(file, "sfbk"));
try (RIFFWriter writer = new RIFFWriter(file, "sfbk")) {
writeSoundbank(writer);
}
}

public void save(OutputStream out) throws IOException {
writeSoundbank(new RIFFWriter(out, "sfbk"));
try (RIFFWriter writer = new RIFFWriter(out, "sfbk")) {
writeSoundbank(writer);
}
}

private void writeSoundbank(RIFFWriter writer) throws IOException {
writeInfo(writer.writeList("INFO"));
writeSdtaChunk(writer.writeList("sdta"));
writePdtaChunk(writer.writeList("pdta"));
writer.close();
}

private void writeInfoStringChunk(RIFFWriter writer, String name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -787,8 +787,12 @@ public InputStream run() {
if (out != null) {
try {
((SF2Soundbank) defaultSoundBank).save(out);
out.close();
} catch (final IOException ignored) {
} finally {
try {
out.close();
} catch (final IOException ignored) {
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -145,34 +145,27 @@ private MidiFileFormat getMidiFileFormatFromStream(InputStream stream,


public MidiFileFormat getMidiFileFormat(URL url) throws InvalidMidiDataException, IOException {
InputStream urlStream = url.openStream(); // throws IOException
BufferedInputStream bis = new BufferedInputStream( urlStream, bisBufferSize );
MidiFileFormat fileFormat = null;
try {
fileFormat = getMidiFileFormat( bis ); // throws InvalidMidiDataException
} finally {
bis.close();
try (InputStream urlStream = url.openStream(); // throws IOException
BufferedInputStream bis = new BufferedInputStream(urlStream, bisBufferSize))
{
MidiFileFormat fileFormat = getMidiFileFormat(bis); // throws InvalidMidiDataException
return fileFormat;
}
return fileFormat;
}


public MidiFileFormat getMidiFileFormat(File file) throws InvalidMidiDataException, IOException {
FileInputStream fis = new FileInputStream(file); // throws IOException
BufferedInputStream bis = new BufferedInputStream(fis, bisBufferSize);

// $$fb 2002-04-17: part of fix for 4635286: MidiSystem.getMidiFileFormat() returns format having invalid length
long length = file.length();
if (length > Integer.MAX_VALUE) {
length = MidiFileFormat.UNKNOWN_LENGTH;
}
MidiFileFormat fileFormat = null;
try {
fileFormat = getMidiFileFormatFromStream(bis, (int) length, null);
} finally {
bis.close();
try (FileInputStream fis = new FileInputStream(file); // throws IOException
BufferedInputStream bis = new BufferedInputStream(fis, bisBufferSize))
{
// $$fb 2002-04-17: part of fix for 4635286: MidiSystem.getMidiFileFormat() returns format having invalid length
long length = file.length();
if (length > Integer.MAX_VALUE) {
length = MidiFileFormat.UNKNOWN_LENGTH;
}
MidiFileFormat fileFormat = getMidiFileFormatFromStream(bis, (int) length, null);
return fileFormat;
}
return fileFormat;
}


Expand Down Expand Up @@ -204,28 +197,22 @@ public Sequence getSequence(InputStream stream) throws InvalidMidiDataException,


public Sequence getSequence(URL url) throws InvalidMidiDataException, IOException {
InputStream is = url.openStream(); // throws IOException
is = new BufferedInputStream(is, bisBufferSize);
Sequence seq = null;
try {
seq = getSequence(is);
} finally {
is.close();
try (InputStream is = url.openStream(); // throws IOException
BufferedInputStream bis = new BufferedInputStream(is, bisBufferSize))
{
Sequence seq = getSequence(bis);
return seq;
}
return seq;
}


public Sequence getSequence(File file) throws InvalidMidiDataException, IOException {
InputStream is = new FileInputStream(file); // throws IOException
is = new BufferedInputStream(is, bisBufferSize);
Sequence seq = null;
try {
seq = getSequence(is);
} finally {
is.close();
try (InputStream is = new FileInputStream(file); // throws IOException
BufferedInputStream bis = new BufferedInputStream(is, bisBufferSize))
{
Sequence seq = getSequence(bis);
return seq;
}
return seq;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ public int write(Sequence in, int type, OutputStream out) throws IOException {
}

public int write(Sequence in, int type, File out) throws IOException {
FileOutputStream fos = new FileOutputStream(out); // throws IOException
int bytesWritten = write( in, type, fos );
fos.close();
return bytesWritten;
try (FileOutputStream fos = new FileOutputStream(out)) { // throws IOException
int bytesWritten = write(in, type, fos);
return bytesWritten;
}
}

//=================================================================================
Expand Down
Loading