Skip to content

Commit 073f20e

Browse files
author
Bruce Eckel
committed
Reorganized network appendix. try-with-finally reformatting
1 parent 13a6e2c commit 073f20e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+438
-324
lines changed

annotations/ifx/IfaceExtractorProcessor.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ public class IfaceExtractorProcessor
5050
}
5151
private void
5252
writeInterfaceFile(String interfaceName) {
53-
try(Writer writer = processingEnv.getFiler()
54-
.createSourceFile(interfaceName)
55-
.openWriter()) {
53+
try(
54+
Writer writer = processingEnv.getFiler()
55+
.createSourceFile(interfaceName)
56+
.openWriter()
57+
) {
5658
String packageName = elementUtils
5759
.getPackageOf(interfaceMethods
5860
.get(0)).toString();

compression/GZIPcompress.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,25 @@ public class GZIPcompress {
1717
"the file to test.gz");
1818
System.exit(1);
1919
}
20-
try(InputStream in = new BufferedInputStream(
21-
new FileInputStream(args[0]));
22-
BufferedOutputStream out =
23-
new BufferedOutputStream(
24-
new GZIPOutputStream(
25-
new FileOutputStream("test.gz")))) {
20+
try(
21+
InputStream in = new BufferedInputStream(
22+
new FileInputStream(args[0]));
23+
BufferedOutputStream out =
24+
new BufferedOutputStream(
25+
new GZIPOutputStream(
26+
new FileOutputStream("test.gz")))
27+
) {
2628
System.out.println("Writing file");
2729
int c;
2830
while((c = in.read()) != -1)
2931
out.write(c);
3032
}
3133
System.out.println("Reading file");
32-
try(BufferedReader in2 = new BufferedReader(
33-
new InputStreamReader(new GZIPInputStream(
34-
new FileInputStream("test.gz"))))) {
34+
try(
35+
BufferedReader in2 = new BufferedReader(
36+
new InputStreamReader(new GZIPInputStream(
37+
new FileInputStream("test.gz"))))
38+
) {
3539
String s;
3640
while((s = in2.readLine()) != null)
3741
System.out.println(s);

compression/ZipCompress.java

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,23 @@
1313
public class ZipCompress {
1414
public static void
1515
main(String[] args) throws IOException {
16-
try(FileOutputStream f =
17-
new FileOutputStream("test.zip");
18-
CheckedOutputStream csum =
19-
new CheckedOutputStream(f, new Adler32());
20-
ZipOutputStream zos = new ZipOutputStream(csum);
21-
BufferedOutputStream out =
22-
new BufferedOutputStream(zos)) {
16+
try(
17+
FileOutputStream f =
18+
new FileOutputStream("test.zip");
19+
CheckedOutputStream csum =
20+
new CheckedOutputStream(f, new Adler32());
21+
ZipOutputStream zos = new ZipOutputStream(csum);
22+
BufferedOutputStream out =
23+
new BufferedOutputStream(zos)
24+
) {
2325
zos.setComment("A test of Java Zipping");
2426
// No corresponding getComment(), though.
2527
for(String arg : args) {
2628
System.out.println("Writing file " + arg);
27-
try(InputStream in = new BufferedInputStream(
28-
new FileInputStream(arg))) {
29+
try(
30+
InputStream in = new BufferedInputStream(
31+
new FileInputStream(arg))
32+
) {
2933
zos.putNextEntry(new ZipEntry(arg));
3034
int c;
3135
while((c = in.read()) != -1)
@@ -39,13 +43,15 @@ public class ZipCompress {
3943
}
4044
// Now extract the files:
4145
System.out.println("Reading file");
42-
try(FileInputStream fi =
43-
new FileInputStream("test.zip");
44-
CheckedInputStream csumi =
45-
new CheckedInputStream(fi, new Adler32());
46-
ZipInputStream in2 = new ZipInputStream(csumi);
47-
BufferedInputStream bis =
48-
new BufferedInputStream(in2)) {
46+
try(
47+
FileInputStream fi =
48+
new FileInputStream("test.zip");
49+
CheckedInputStream csumi =
50+
new CheckedInputStream(fi, new Adler32());
51+
ZipInputStream in2 = new ZipInputStream(csumi);
52+
BufferedInputStream bis =
53+
new BufferedInputStream(in2)
54+
) {
4955
ZipEntry ze;
5056
while((ze = in2.getNextEntry()) != null) {
5157
System.out.println("Reading file " + ze);
@@ -58,7 +64,9 @@ public class ZipCompress {
5864
"Checksum: "+csumi.getChecksum().getValue());
5965
}
6066
// Alternative way to open and read Zip files:
61-
try(ZipFile zf = new ZipFile("test.zip")) {
67+
try(
68+
ZipFile zf = new ZipFile("test.zip")
69+
) {
6270
Enumeration e = zf.entries();
6371
while(e.hasMoreElements()) {
6472
ZipEntry ze2 = (ZipEntry)e.nextElement();

exceptions/AutoCloseableDetails.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ class Second extends Reporter {}
1818

1919
public class AutoCloseableDetails {
2020
public static void main(String[] args) {
21-
try(First f = new First();
22-
Second s = new Second()) {
21+
try(
22+
First f = new First();
23+
Second s = new Second()
24+
) {
2325
}
2426
}
2527
}

exceptions/BodyException.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ class Third extends Reporter {}
77

88
public class BodyException {
99
public static void main(String[] args) {
10-
try(First f = new First();
11-
Second s2 = new Second()) {
10+
try(
11+
First f = new First();
12+
Second s2 = new Second()
13+
) {
1214
System.out.println("In body");
1315
Third t = new Third();
1416
new SecondExcept();

exceptions/CloseExceptions.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ public void close() throws CloseException {
2525

2626
public class CloseExceptions {
2727
public static void main(String[] args) {
28-
try(First f = new First();
29-
Closer c = new Closer();
30-
Second s = new Second()) {
28+
try(
29+
First f = new First();
30+
Closer c = new Closer();
31+
Second s = new Second()
32+
) {
3133
System.out.println("In body");
3234
} catch(CloseException e) {
3335
System.out.println("Caught: " + e);

exceptions/ConstructorException.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ public SecondExcept() throws CE {
1414

1515
public class ConstructorException {
1616
public static void main(String[] args) {
17-
try(First f = new First();
18-
SecondExcept s = new SecondExcept();
19-
Second s2 = new Second()) {
17+
try(
18+
First f = new First();
19+
SecondExcept s = new SecondExcept();
20+
Second s2 = new Second()
21+
) {
2022
System.out.println("In body");
2123
} catch(CE e) {
2224
System.out.println("Caught: " + e);

exceptions/StreamsAreAutoCloseable.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
public class StreamsAreAutoCloseable {
1010
public static void
1111
main(String[] args) throws IOException{
12-
try(Stream<String> in = Files.lines(
13-
Paths.get("StreamsAreAutoCloseable.java"));
14-
PrintWriter outfile = new PrintWriter(
15-
"Results.txt");) { // (1)
12+
try(
13+
Stream<String> in = Files.lines(
14+
Paths.get("StreamsAreAutoCloseable.java"));
15+
PrintWriter outfile = new PrintWriter(
16+
"Results.txt"); // (1)
17+
) {
1618
in.skip(5)
1719
.limit(1)
1820
.map(String::toLowerCase)

exceptions/TryAnything.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ class Anything {}
88

99
public class TryAnything {
1010
public static void main(String[] args) {
11-
try(Anything a = new Anything()) {
11+
try(
12+
Anything a = new Anything()
13+
) {
1214
}
1315
}
1416
}

exceptions/TryWithResources.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66

77
public class TryWithResources {
88
public static void main(String[] args) {
9-
try(InputStream in = new FileInputStream(
10-
new File("TryWithResources.java"))) {
9+
try(
10+
InputStream in = new FileInputStream(
11+
new File("TryWithResources.java"))
12+
) {
1113
int contents = in.read();
1214
// Process contents
1315
} catch(IOException e) {

0 commit comments

Comments
 (0)