-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Java: simplify the generated XDR code. (#198)
* Java: remove the static encode method. * Java: no longer import all constants.
- Loading branch information
Showing
76 changed files
with
279 additions
and
1,347 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
package <%= @namespace %>; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import org.stellar.sdk.Base64Factory; | ||
|
||
/** | ||
* Common parent interface for all generated classes. | ||
*/ | ||
/** Common parent interface for all generated classes. */ | ||
interface XdrElement { | ||
void encode(XdrDataOutputStream stream) throws IOException; | ||
void encode(XdrDataOutputStream stream) throws IOException; | ||
|
||
String toXdrBase64() throws IOException; | ||
default String toXdrBase64() throws IOException { | ||
return Base64Factory.getInstance().encodeToString(toXdrByteArray()); | ||
} | ||
|
||
byte[] toXdrByteArray() throws IOException; | ||
} | ||
default byte[] toXdrByteArray() throws IOException { | ||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); | ||
encode(xdrDataOutputStream); | ||
return byteArrayOutputStream.toByteArray(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 13 additions & 6 deletions
19
spec/output/generator_spec_java/block_comments.x/XdrElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
package MyXDR; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import org.stellar.sdk.Base64Factory; | ||
|
||
/** | ||
* Common parent interface for all generated classes. | ||
*/ | ||
/** Common parent interface for all generated classes. */ | ||
interface XdrElement { | ||
void encode(XdrDataOutputStream stream) throws IOException; | ||
void encode(XdrDataOutputStream stream) throws IOException; | ||
|
||
String toXdrBase64() throws IOException; | ||
default String toXdrBase64() throws IOException { | ||
return Base64Factory.getInstance().encodeToString(toXdrByteArray()); | ||
} | ||
|
||
byte[] toXdrByteArray() throws IOException; | ||
default byte[] toXdrByteArray() throws IOException { | ||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream); | ||
encode(xdrDataOutputStream); | ||
return byteArrayOutputStream.toByteArray(); | ||
} | ||
} |
Oops, something went wrong.