Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
3239fec9
Commit
3239fec9
authored
Jun 07, 2011
by
liujisi@google.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Close resources properly for java tests and examples.
parent
e8e6eed0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
10 deletions
+25
-10
AddPerson.java
examples/AddPerson.java
+10
-4
GeneratedMessageTest.java
...c/test/java/com/google/protobuf/GeneratedMessageTest.java
+10
-4
LiteTest.java
java/src/test/java/com/google/protobuf/LiteTest.java
+5
-2
No files found.
examples/AddPerson.java
View file @
3239fec9
...
...
@@ -70,8 +70,11 @@ class AddPerson {
// Read the existing address book.
try
{
FileInputStream
input
=
new
FileInputStream
(
args
[
0
]);
addressBook
.
mergeFrom
(
input
);
input
.
close
();
try
{
addressBook
.
mergeFrom
(
input
);
}
finally
{
try
{
input
.
close
();
}
catch
(
Throwable
ignore
)
{}
}
}
catch
(
FileNotFoundException
e
)
{
System
.
out
.
println
(
args
[
0
]
+
": File not found. Creating a new file."
);
}
...
...
@@ -83,7 +86,10 @@ class AddPerson {
// Write the new address book back to disk.
FileOutputStream
output
=
new
FileOutputStream
(
args
[
0
]);
addressBook
.
build
().
writeTo
(
output
);
output
.
close
();
try
{
addressBook
.
build
().
writeTo
(
output
);
}
finally
{
output
.
close
();
}
}
}
java/src/test/java/com/google/protobuf/GeneratedMessageTest.java
View file @
3239fec9
...
...
@@ -775,8 +775,11 @@ public class GeneratedMessageTest extends TestCase {
TestUtil
.
setAllFields
(
builder
);
TestAllTypes
expected
=
builder
.
build
();
ObjectOutputStream
out
=
new
ObjectOutputStream
(
baos
);
out
.
writeObject
(
expected
);
out
.
close
();
try
{
out
.
writeObject
(
expected
);
}
finally
{
out
.
close
();
}
ByteArrayInputStream
bais
=
new
ByteArrayInputStream
(
baos
.
toByteArray
());
ObjectInputStream
in
=
new
ObjectInputStream
(
bais
);
TestAllTypes
actual
=
(
TestAllTypes
)
in
.
readObject
();
...
...
@@ -788,8 +791,11 @@ public class GeneratedMessageTest extends TestCase {
TestAllTypes
.
Builder
builder
=
TestAllTypes
.
newBuilder
();
TestAllTypes
expected
=
builder
.
buildPartial
();
ObjectOutputStream
out
=
new
ObjectOutputStream
(
baos
);
out
.
writeObject
(
expected
);
out
.
close
();
try
{
out
.
writeObject
(
expected
);
}
finally
{
out
.
close
();
}
ByteArrayInputStream
bais
=
new
ByteArrayInputStream
(
baos
.
toByteArray
());
ObjectInputStream
in
=
new
ObjectInputStream
(
bais
);
TestAllTypes
actual
=
(
TestAllTypes
)
in
.
readObject
();
...
...
java/src/test/java/com/google/protobuf/LiteTest.java
View file @
3239fec9
...
...
@@ -129,8 +129,11 @@ public class LiteTest extends TestCase {
TestAllTypesLite
.
NestedMessage
.
newBuilder
().
setBb
(
7
))
.
build
();
ObjectOutputStream
out
=
new
ObjectOutputStream
(
baos
);
out
.
writeObject
(
expected
);
out
.
close
();
try
{
out
.
writeObject
(
expected
);
}
finally
{
out
.
close
();
}
ByteArrayInputStream
bais
=
new
ByteArrayInputStream
(
baos
.
toByteArray
());
ObjectInputStream
in
=
new
ObjectInputStream
(
bais
);
TestAllTypesLite
actual
=
(
TestAllTypesLite
)
in
.
readObject
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment