Coverage Summary for Class: VMUtils (org.ethereum.vm)
Class |
Class, %
|
Method, %
|
Line, %
|
VMUtils |
0%
(0/1)
|
0%
(0/3)
|
0%
(0/16)
|
1 /*
2 * This file is part of RskJ
3 * Copyright (C) 2017 RSK Labs Ltd.
4 * (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>)
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 package org.ethereum.vm;
21
22 import org.ethereum.vm.trace.ProgramTrace;
23 import org.ethereum.vm.trace.Serializers;
24
25 import java.io.File;
26 import java.io.FileOutputStream;
27 import java.io.IOException;
28 import java.io.OutputStream;
29 import java.nio.file.Files;
30 import java.nio.file.Path;
31 import java.nio.file.Paths;
32 import java.util.zip.ZipEntry;
33 import java.util.zip.ZipOutputStream;
34
35 public final class VMUtils {
36 private VMUtils() {
37 }
38
39 public static void saveProgramTraceFile(Path basePath, String txHash, boolean compress, ProgramTrace trace) throws IOException {
40 if (compress) {
41 try(final FileOutputStream fos = new FileOutputStream(basePath.resolve(txHash + ".zip").toFile());
42 final ZipOutputStream zos = new ZipOutputStream(fos)
43 ) {
44 ZipEntry zipEntry = new ZipEntry(txHash + ".json");
45 zos.putNextEntry(zipEntry);
46 Serializers.serializeFieldsOnly(trace, true, zos);
47 }
48 } else {
49 try (final OutputStream out = Files.newOutputStream(basePath.resolve(txHash + ".json"))) {
50 Serializers.serializeFieldsOnly(trace, true, out);
51 }
52 }
53 }
54
55 public static void saveProgramTraceFile(String txHash, ProgramTrace trace, String databaseDir, String vmTraceDir, boolean vmTraceCompressed) throws IOException {
56 Path tracePath = Paths.get(databaseDir, vmTraceDir);
57 File traceDir = tracePath.toFile();
58 if (!traceDir.exists()) {
59 traceDir.mkdirs();
60 }
61 saveProgramTraceFile(tracePath, txHash, vmTraceCompressed, trace);
62 }
63 }