Skip to content

Commit 95a3df9

Browse files
Merge pull request #255 from CycloneDX/improve_code
Improve Code
2 parents ea30e63 + eee287c commit 95a3df9

File tree

7 files changed

+24
-27
lines changed

7 files changed

+24
-27
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ as well as the output format options. Use the latest possible version of this li
3232
the CycloneDX version supported by the target system.
3333

3434
| Version | Schema Version | Format(s) |
35-
| ------- | ----------------- | --------- |
36-
| 7.x | CycloneDX v1.4 | XML/JSON |
37-
| 6.x | CycloneDX v1.4 | XML/JSON |
38-
| 5.x | CycloneDX v1.3 | XML/JSON |
39-
| 4.x | CycloneDX v1.2 | XML/JSON |
40-
| 3.x | CycloneDX v1.2 | XML/JSON |
41-
| 2.x | CycloneDX v1.1 | XML |
42-
| 1.x | CycloneDX v1.0 | XML |
35+
|---------|----------------|-----------|
36+
| 7.x | CycloneDX v1.4 | XML/JSON |
37+
| 6.x | CycloneDX v1.4 | XML/JSON |
38+
| 5.x | CycloneDX v1.3 | XML/JSON |
39+
| 4.x | CycloneDX v1.2 | XML/JSON |
40+
| 3.x | CycloneDX v1.2 | XML/JSON |
41+
| 2.x | CycloneDX v1.1 | XML |
42+
| 1.x | CycloneDX v1.0 | XML |
4343

4444
## Library API Documentation
4545

src/main/java/org/cyclonedx/BomParserFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@
2424
import org.cyclonedx.parsers.Parser;
2525
import org.cyclonedx.parsers.XmlParser;
2626
import java.io.File;
27-
import java.io.FileInputStream;
2827
import java.io.IOException;
2928
import java.io.InputStream;
3029
import java.nio.charset.StandardCharsets;
30+
import java.nio.file.Files;
3131

3232
public class BomParserFactory {
3333

3434
private BomParserFactory() {}
3535

3636
public static Parser createParser(final File file) throws ParseException {
37-
try (final InputStream fis = new FileInputStream(file)) {
37+
try (final InputStream fis = Files.newInputStream(file.toPath())) {
3838
final byte[] bytes = IOUtils.toByteArray(fis, 1);
3939
return createParser(bytes);
4040
} catch (IOException e) {

src/main/java/org/cyclonedx/generators/json/AbstractBomJsonGenerator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ public AbstractBomJsonGenerator() {
5050
setupPrettyPrinter(this.prettyPrinter);
5151
}
5252

53-
public ObjectMapper getMapper() {
54-
return mapper;
55-
}
53+
public ObjectMapper getMapper() {
54+
return mapper;
55+
}
5656

5757
private void setupPrettyPrinter(final DefaultPrettyPrinter prettyPrinter) {
5858
prettyPrinter.indentArraysWith(DefaultIndenter.SYSTEM_LINEFEED_INSTANCE);

src/main/java/org/cyclonedx/generators/xml/AbstractBomXmlGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ String toXML(final Bom bom, final boolean prettyPrint) throws GeneratorException
129129
/**
130130
* Creates a text representation of a CycloneDX BoM Document. This method
131131
* calls {@link #toXmlString()} and will return an empty string if {@link #toXmlString()}
132-
* throws an exception. Its preferred to call {@link #toXmlString()} directly
132+
* throws an exception. It's preferred to call {@link #toXmlString()} directly
133133
* so that exceptions can be caught.
134134
* @return a String of the BoM
135135
* @since 1.1.0

src/main/java/org/cyclonedx/parsers/XmlParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@
4040
import javax.xml.xpath.XPathFactory;
4141
import java.io.ByteArrayInputStream;
4242
import java.io.File;
43-
import java.io.FileInputStream;
4443
import java.io.IOException;
4544
import java.io.InputStream;
4645
import java.io.Reader;
4746
import java.lang.reflect.Field;
47+
import java.nio.file.Files;
4848
import java.util.LinkedList;
4949
import java.util.List;
5050

@@ -68,7 +68,7 @@ public XmlParser() {
6868
public Bom parse(final File file) throws ParseException {
6969
try {
7070
final String schemaVersion = identifySchemaVersion(
71-
extractAllNamespaceDeclarations(new InputSource(new FileInputStream(file))));
71+
extractAllNamespaceDeclarations(new InputSource(Files.newInputStream(file.toPath()))));
7272

7373
return injectSchemaVersion(mapper.readValue(file, Bom.class), schemaVersion);
7474
} catch (IOException | XPathExpressionException e) {

src/test/java/org/cyclonedx/parse/JsonParseTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,21 @@
2929
import static org.junit.jupiter.api.Assertions.assertNotNull;
3030

3131
public class JsonParseTest extends BaseParseTest {
32-
3332
@TestFactory
34-
public Collection<DynamicTest> dynamicTestsWithCollection() throws Exception {
33+
public Collection<DynamicTest> dynamicTestsWithCollection() {
3534
final List<File> files = getAllResources();
3635
final List<DynamicTest> dynamicTests = new ArrayList<>();
37-
for (final File file: files) {
36+
for (final File file : files) {
3837
if (file.getName().endsWith(".json")) {
3938
if (file.getName().startsWith("valid")) {
4039
//dynamicTests.add(DynamicTest.dynamicTest(file.getName(), () -> assertNotNull(parseBom(file))));
4140
dynamicTests.add(DynamicTest.dynamicTest(file.getName(), () -> {
4241
final Bom bom = parseBom(file);
4342
assertNotNull(bom);
4443
super.generateBomJson(file.getName(), bom);
45-
4644
}));
47-
} else if (file.getName().startsWith("invalid")) {
45+
}
46+
else if (file.getName().startsWith("invalid")) {
4847

4948
}
5049
}

src/test/java/org/cyclonedx/parse/XmlParseTest.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,25 @@
2929
import static org.junit.jupiter.api.Assertions.assertNotNull;
3030

3131
public class XmlParseTest extends BaseParseTest {
32-
3332
@TestFactory
34-
public Collection<DynamicTest> dynamicTestsWithCollection() throws Exception {
33+
public Collection<DynamicTest> dynamicTestsWithCollection() {
3534
final List<File> files = getAllResources();
3635
final List<DynamicTest> dynamicTests = new ArrayList<>();
37-
for (final File file: files) {
36+
for (final File file : files) {
3837
if (file.getName().endsWith(".xml")) {
3938
if (file.getName().startsWith("valid")) {
4039
//dynamicTests.add(DynamicTest.dynamicTest(file.getName(), () -> assertNotNull(parseBom(file))));
4140
dynamicTests.add(DynamicTest.dynamicTest(file.getName(), () -> {
4241
final Bom bom = parseBom(file);
4342
assertNotNull(bom);
4443
super.generateBomXml(file.getName(), bom);
45-
4644
}));
47-
} else if (file.getName().startsWith("invalid")) {
45+
}
46+
else if (file.getName().startsWith("invalid")) {
4847

4948
}
5049
}
5150
}
5251
return dynamicTests;
5352
}
54-
5553
}

0 commit comments

Comments
 (0)