Skip to content

Commit 7a697f8

Browse files
committed
[Java] Address issue with template not being found and closing resource, plus fix some spellings.
1 parent 1793c8a commit 7a697f8

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/golang/GolangGenerator.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import uk.co.real_logic.sbe.ir.*;
2323
import org.agrona.Verify;
2424

25+
import java.io.BufferedInputStream;
2526
import java.io.IOException;
2627
import java.io.InputStream;
2728
import java.io.Writer;
@@ -1444,9 +1445,7 @@ private void generateEnum(final List<Token> tokens) throws IOException
14441445
}
14451446
}
14461447

1447-
private void generateComposite(
1448-
final List<Token> tokens,
1449-
final String namePrefix) throws IOException
1448+
private void generateComposite(final List<Token> tokens, final String namePrefix) throws IOException
14501449
{
14511450
final String compositeName = namePrefix + formatTypeName(tokens.get(0).applicableTypeName());
14521451
final StringBuilder sb = new StringBuilder();
@@ -1580,14 +1579,12 @@ private void generateChoiceDecls(
15801579
sb.append("}\n");
15811580
}
15821581

1583-
private String namespacesToPackageName(
1584-
final CharSequence[] namespaces)
1582+
private String namespacesToPackageName(final CharSequence[] namespaces)
15851583
{
15861584
return String.join("_", namespaces).toLowerCase().replace('.', '_').replace(' ', '_').replace('-', '_');
15871585
}
15881586

1589-
private StringBuilder generateFileHeader(
1590-
final CharSequence[] namespaces)
1587+
private StringBuilder generateFileHeader(final CharSequence[] namespaces)
15911588
{
15921589
final StringBuilder sb = new StringBuilder();
15931590
sb.append("// Generated SBE (Simple Binary Encoding) message codec\n\n");
@@ -1611,17 +1608,19 @@ private String generateFromTemplate(final CharSequence[] namespaces, final Strin
16111608
throws IOException
16121609
{
16131610
final String jarFile = "golang/templates/" + templateName + ".go";
1614-
final InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(jarFile);
1615-
final Scanner s = new Scanner(inputStream).useDelimiter("\\A");
1616-
final String template = s.hasNext() ? s.next() : "";
1617-
inputStream.close();
1611+
try (InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(jarFile))
1612+
{
1613+
final Scanner scanner = new Scanner(new BufferedInputStream(inputStream)).useDelimiter("\\A");
1614+
if (!scanner.hasNext())
1615+
{
1616+
return "";
1617+
}
16181618

1619-
return String.format(template, namespacesToPackageName(namespaces));
1619+
return String.format(scanner.next(), namespacesToPackageName(namespaces));
1620+
}
16201621
}
16211622

1622-
private static void generateTypeDeclaration(
1623-
final StringBuilder sb,
1624-
final String typeName)
1623+
private static void generateTypeDeclaration(final StringBuilder sb, final String typeName)
16251624
{
16261625
sb.append(String.format("type %s struct {\n", typeName));
16271626
}

sbe-tool/src/main/resources/golang/templates/SbeMarshallingBigEndian.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414
//
15-
// This file provides a simple bespoke marhalling layer for the
15+
// This file provides a simple bespoke marshalling layer for the
1616
// standard binary encoding golang backend and is part of:
1717
//
1818
// https://github.com/real-logic/simple-binary-encoding

sbe-tool/src/main/resources/golang/templates/SbeMarshallingLittleEndian.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414
//
15-
// This file provides a simple bespoke marhalling layer for the
15+
// This file provides a simple bespoke marshalling layer for the
1616
// standard binary encoding golang backend and is part of:
1717
//
1818
// https://github.com/real-logic/simple-binary-encoding

0 commit comments

Comments
 (0)