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.notedb; 16 : 17 : import static java.nio.charset.StandardCharsets.UTF_8; 18 : 19 : import com.google.gerrit.entities.RobotComment; 20 : import java.io.ByteArrayInputStream; 21 : import java.io.IOException; 22 : import java.io.InputStream; 23 : import java.io.InputStreamReader; 24 : import java.io.Reader; 25 : import java.util.List; 26 : import org.eclipse.jgit.lib.ObjectId; 27 : import org.eclipse.jgit.lib.ObjectReader; 28 : 29 : /** 30 : * Holds the raw data of a RevisionNote. 31 : * 32 : * <p>It is intended for deserialization from JSON only. It is used for robot comments only. 33 : */ 34 : public class RobotCommentsRevisionNote extends RevisionNote<RobotComment> { 35 : private final ChangeNoteJson noteUtil; 36 : 37 : RobotCommentsRevisionNote(ChangeNoteJson noteUtil, ObjectReader reader, ObjectId noteId) { 38 9 : super(reader, noteId); 39 9 : this.noteUtil = noteUtil; 40 9 : } 41 : 42 : @Override 43 : protected List<RobotComment> parse(byte[] raw, int offset) throws IOException { 44 9 : try (InputStream is = new ByteArrayInputStream(raw, offset, raw.length - offset); 45 9 : Reader r = new InputStreamReader(is, UTF_8)) { 46 9 : return noteUtil.getGson().fromJson(r, RobotCommentsRevisionNoteData.class).comments; 47 : } 48 : } 49 : }