Line data Source code
1 : // Copyright (C) 2016 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.server.patch; 16 : 17 : import static com.google.gerrit.server.ioutil.BasicSerialization.readString; 18 : import static com.google.gerrit.server.ioutil.BasicSerialization.readVarInt32; 19 : import static com.google.gerrit.server.ioutil.BasicSerialization.writeString; 20 : import static com.google.gerrit.server.ioutil.BasicSerialization.writeVarInt32; 21 : 22 : import com.google.gerrit.server.query.change.ChangeData.ChangedLines; 23 : import java.io.IOException; 24 : import java.io.ObjectInputStream; 25 : import java.io.ObjectOutputStream; 26 : import java.io.Serializable; 27 : import java.util.Arrays; 28 : import java.util.Collections; 29 : import java.util.List; 30 : import java.util.zip.DeflaterOutputStream; 31 : import java.util.zip.InflaterInputStream; 32 : 33 : public class DiffSummary implements Serializable { 34 : private static final long serialVersionUID = DiffSummaryKey.serialVersionUID; 35 : 36 : private transient String[] paths; 37 : private transient int insertions; 38 : private transient int deletions; 39 : 40 103 : public DiffSummary(String[] paths, int insertions, int deletions) { 41 103 : this.paths = paths; 42 103 : this.insertions = insertions; 43 103 : this.deletions = deletions; 44 103 : } 45 : 46 : public List<String> getPaths() { 47 103 : return Collections.unmodifiableList(Arrays.asList(paths)); 48 : } 49 : 50 : public ChangedLines getChangedLines() { 51 103 : return new ChangedLines(insertions, deletions); 52 : } 53 : 54 : private void writeObject(ObjectOutputStream output) throws IOException { 55 6 : writeVarInt32(output, insertions); 56 6 : writeVarInt32(output, deletions); 57 6 : writeVarInt32(output, paths.length); 58 6 : try (DeflaterOutputStream out = new DeflaterOutputStream(output)) { 59 6 : for (String p : paths) { 60 4 : writeString(out, p); 61 : } 62 : } 63 6 : } 64 : 65 : private void readObject(ObjectInputStream input) throws IOException { 66 1 : insertions = readVarInt32(input); 67 1 : deletions = readVarInt32(input); 68 1 : paths = new String[readVarInt32(input)]; 69 1 : try (InflaterInputStream in = new InflaterInputStream(input)) { 70 1 : for (int i = 0; i < paths.length; i++) { 71 0 : paths[i] = readString(in); 72 : } 73 : } 74 1 : } 75 : }