diff --git a/core/src/main/java/org/bitcoinj/wallet/WalletProtobufSerializer.java b/core/src/main/java/org/bitcoinj/wallet/WalletProtobufSerializer.java index 324863b6..cbe9a58c 100644 --- a/core/src/main/java/org/bitcoinj/wallet/WalletProtobufSerializer.java +++ b/core/src/main/java/org/bitcoinj/wallet/WalletProtobufSerializer.java @@ -31,6 +31,7 @@ import org.bitcoinj.wallet.Protos.Wallet.EncryptionType; import com.google.common.collect.Lists; import com.google.protobuf.ByteString; import com.google.protobuf.CodedInputStream; +import com.google.protobuf.CodedOutputStream; import com.google.protobuf.TextFormat; import com.google.protobuf.WireFormat; @@ -78,6 +79,7 @@ public class WalletProtobufSerializer { protected Map txMap; private boolean requireMandatoryExtensions = true; + private int walletWriteBufferSize = CodedOutputStream.DEFAULT_BUFFER_SIZE; public interface WalletFactory { Wallet create(NetworkParameters params, KeyChainGroup keyChainGroup); @@ -114,6 +116,14 @@ public class WalletProtobufSerializer { requireMandatoryExtensions = value; } + /** + * Change buffer size for writing wallet to output stream. Default is {@link com.google.protobuf.CodedOutputStream.DEFAULT_BUFFER_SIZE} + * @param walletWriteBufferSize - buffer size in bytes + */ + public void setWalletWriteBufferSize(int walletWriteBufferSize) { + this.walletWriteBufferSize = walletWriteBufferSize; + } + /** * Formats the given wallet (transactions and keys) to the given output stream in protocol buffer format.

* @@ -121,7 +131,9 @@ public class WalletProtobufSerializer { */ public void writeWallet(Wallet wallet, OutputStream output) throws IOException { Protos.Wallet walletProto = walletToProto(wallet); - walletProto.writeTo(output); + final CodedOutputStream codedOutput = CodedOutputStream.newInstance(output, this.walletWriteBufferSize); + walletProto.writeTo(codedOutput); + codedOutput.flush(); } /**