Skip to content

Commit 88ae704

Browse files
github-actionsgithub-actions
authored andcommitted
Formatted with Google Java Formatter
1 parent 93b4e82 commit 88ae704

File tree

10 files changed

+92
-102
lines changed

10 files changed

+92
-102
lines changed
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
package com.examplehub.basics.io;
22

3-
public class CharArrayReaderExample {
4-
}
3+
public class CharArrayReaderExample {}
Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
package com.examplehub.basics.io;
22

33
import com.examplehub.utils.StringUtils;
4-
5-
import java.io.FileNotFoundException;
64
import java.io.FileReader;
75
import java.io.IOException;
86
import java.io.Reader;
97

108
public class FileReaderExample {
11-
public static String read(String filename) throws IOException {
12-
try (Reader reader = new FileReader(filename)) {
13-
char[] chars = new char[1024];
14-
StringBuilder builder = new StringBuilder();
15-
int len;
16-
while ((len = reader.read(chars)) != -1) {
17-
builder.append(StringUtils.toString(chars, 0, len));
18-
}
19-
return builder.toString();
20-
}
9+
public static String read(String filename) throws IOException {
10+
try (Reader reader = new FileReader(filename)) {
11+
char[] chars = new char[1024];
12+
StringBuilder builder = new StringBuilder();
13+
int len;
14+
while ((len = reader.read(chars)) != -1) {
15+
builder.append(StringUtils.toString(chars, 0, len));
16+
}
17+
return builder.toString();
2118
}
19+
}
2220
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
package com.examplehub.basics.io;
22

3-
public class FileWriterExample {
4-
5-
}
3+
public class FileWriterExample {}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
package com.examplehub.basics.io;
22

3-
public class StringReaderExample {
4-
}
3+
public class StringReaderExample {}
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
package com.examplehub.utils;
22

33
public class StringUtils {
4-
public static String toString(char[] chars, int offset, int len) {
5-
StringBuilder builder = new StringBuilder();
6-
for (int i = offset; i < offset + len; ++i) {
7-
builder.append(chars[i]);
8-
}
9-
return builder.toString();
4+
public static String toString(char[] chars, int offset, int len) {
5+
StringBuilder builder = new StringBuilder();
6+
for (int i = offset; i < offset + len; ++i) {
7+
builder.append(chars[i]);
108
}
9+
return builder.toString();
10+
}
1111

12-
public static String toString(byte[] bytes, int offset, int len) {
13-
StringBuilder builder = new StringBuilder();
14-
for (int i = offset; i < offset + len; ++i) {
15-
builder.append(bytes[i]);
16-
}
17-
return builder.toString();
12+
public static String toString(byte[] bytes, int offset, int len) {
13+
StringBuilder builder = new StringBuilder();
14+
for (int i = offset; i < offset + len; ++i) {
15+
builder.append(bytes[i]);
1816
}
17+
return builder.toString();
18+
}
1919
}
Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
package com.examplehub.basics.io;
22

3-
import com.examplehub.utils.StringUtils;
4-
import org.junit.jupiter.api.Test;
3+
import static org.junit.jupiter.api.Assertions.*;
54

5+
import com.examplehub.utils.StringUtils;
66
import java.io.CharArrayReader;
77
import java.io.IOException;
88
import java.io.Reader;
9-
10-
import static org.junit.jupiter.api.Assertions.*;
9+
import org.junit.jupiter.api.Test;
1110

1211
class CharArrayReaderExampleTest {
13-
@Test
14-
void test() throws IOException {
15-
try (Reader reader = new CharArrayReader("hello".toCharArray())){
16-
char[] chars = new char[1024];
17-
int len = reader.read(chars);
18-
assertEquals("hello", StringUtils.toString(chars, 0, len));
19-
}
12+
@Test
13+
void test() throws IOException {
14+
try (Reader reader = new CharArrayReader("hello".toCharArray())) {
15+
char[] chars = new char[1024];
16+
int len = reader.read(chars);
17+
assertEquals("hello", StringUtils.toString(chars, 0, len));
2018
}
21-
}
19+
}
20+
}
Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,33 @@
11
package com.examplehub.basics.io;
22

33
import com.examplehub.utils.StringUtils;
4-
import org.junit.jupiter.api.Test;
5-
64
import java.io.FileReader;
75
import java.io.IOException;
86
import java.io.Reader;
97
import java.nio.charset.StandardCharsets;
8+
import org.junit.jupiter.api.Test;
109

1110
class FileReaderExampleTest {
12-
@Test
13-
void testReadChar() throws IOException {
14-
try (Reader reader = new FileReader("pom.xml", StandardCharsets.UTF_8)) {
15-
int ch;
16-
while ((ch = reader.read()) != -1) {
17-
System.out.print((char)ch);
18-
}
19-
}finally {
20-
System.out.println("read completed");
21-
}
11+
@Test
12+
void testReadChar() throws IOException {
13+
try (Reader reader = new FileReader("pom.xml", StandardCharsets.UTF_8)) {
14+
int ch;
15+
while ((ch = reader.read()) != -1) {
16+
System.out.print((char) ch);
17+
}
18+
} finally {
19+
System.out.println("read completed");
2220
}
21+
}
2322

24-
@Test
25-
void testReadChars() throws IOException{
26-
try(Reader reader = new FileReader("pom.xml", StandardCharsets.UTF_8)) {
27-
char[] buffer = new char[1024];
28-
int len = 0;
29-
while ((len = reader.read(buffer)) != -1) {
30-
System.out.print(StringUtils.toString(buffer, 0, len));
31-
}
32-
}
23+
@Test
24+
void testReadChars() throws IOException {
25+
try (Reader reader = new FileReader("pom.xml", StandardCharsets.UTF_8)) {
26+
char[] buffer = new char[1024];
27+
int len = 0;
28+
while ((len = reader.read(buffer)) != -1) {
29+
System.out.print(StringUtils.toString(buffer, 0, len));
30+
}
3331
}
34-
}
32+
}
33+
}
Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
package com.examplehub.basics.io;
22

3-
import org.junit.jupiter.api.Test;
3+
import static org.junit.jupiter.api.Assertions.*;
44

55
import java.io.FileWriter;
66
import java.io.IOException;
77
import java.io.Writer;
88
import java.nio.file.Files;
99
import java.nio.file.Paths;
10-
11-
import static org.junit.jupiter.api.Assertions.*;
10+
import org.junit.jupiter.api.Test;
1211

1312
class FileWriterExampleTest {
14-
@Test
15-
void testWrite() throws IOException {
16-
String fileName = "example.txt";
17-
try (Writer writer = new FileWriter(fileName)) {
18-
writer.write("hello");
19-
}
20-
assertEquals("hello", FileReaderExample.read(fileName));
21-
Files.deleteIfExists(Paths.get("example.txt"));
13+
@Test
14+
void testWrite() throws IOException {
15+
String fileName = "example.txt";
16+
try (Writer writer = new FileWriter(fileName)) {
17+
writer.write("hello");
2218
}
23-
}
19+
assertEquals("hello", FileReaderExample.read(fileName));
20+
Files.deleteIfExists(Paths.get("example.txt"));
21+
}
22+
}
Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
package com.examplehub.basics.io;
22

3-
import com.examplehub.utils.StringUtils;
4-
import org.junit.jupiter.api.Test;
3+
import static org.junit.jupiter.api.Assertions.*;
54

5+
import com.examplehub.utils.StringUtils;
66
import java.io.IOException;
77
import java.io.Reader;
88
import java.io.StringReader;
9-
10-
import static org.junit.jupiter.api.Assertions.*;
9+
import org.junit.jupiter.api.Test;
1110

1211
class StringReaderExampleTest {
13-
@Test
14-
void test() throws IOException {
15-
try (Reader reader = new StringReader("hello")) {
16-
char[] chars = new char[1024];
17-
int len = reader.read(chars);
18-
assertEquals("hello", StringUtils.toString(chars, 0, len));
19-
}
12+
@Test
13+
void test() throws IOException {
14+
try (Reader reader = new StringReader("hello")) {
15+
char[] chars = new char[1024];
16+
int len = reader.read(chars);
17+
assertEquals("hello", StringUtils.toString(chars, 0, len));
2018
}
21-
}
19+
}
20+
}
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
package com.examplehub.utils;
22

3-
import org.junit.jupiter.api.Test;
4-
53
import static org.junit.jupiter.api.Assertions.*;
64

5+
import org.junit.jupiter.api.Test;
6+
77
class StringUtilsTest {
8-
@Test
9-
void testBytesToString() {
10-
byte[] bytes = {1, 2, 3, 4, 5, 0, 0, 0, 0};
11-
assertEquals("234", StringUtils.toString(bytes, 1, 3));
12-
}
8+
@Test
9+
void testBytesToString() {
10+
byte[] bytes = {1, 2, 3, 4, 5, 0, 0, 0, 0};
11+
assertEquals("234", StringUtils.toString(bytes, 1, 3));
12+
}
1313

14-
@Test
15-
void testCharsToString() {
16-
char[] bytes = {'1', '2', '3', '4', '\0', '\0', '\0'};
17-
assertEquals("234", StringUtils.toString(bytes, 1, 3));
18-
}
19-
}
14+
@Test
15+
void testCharsToString() {
16+
char[] bytes = {'1', '2', '3', '4', '\0', '\0', '\0'};
17+
assertEquals("234", StringUtils.toString(bytes, 1, 3));
18+
}
19+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy