1 /* 2 * Copyright (C) 2014 Square, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.squareup.okhttp.internal.framed.hpackjson; 17 18 import com.squareup.okhttp.internal.framed.Header; 19 import okio.ByteString; 20 21 import java.util.ArrayList; 22 import java.util.LinkedHashMap; 23 import java.util.List; 24 import java.util.Map; 25 26 /** 27 * Representation of an individual case (set of headers and wire format). 28 * There are many cases for a single story. This class is used reflectively 29 * with Gson to parse stories. 30 */ 31 public class Case implements Cloneable { 32 33 private int seqno; 34 private String wire; 35 private List<Map<String, String>> headers; 36 getHeaders()37 public List<Header> getHeaders() { 38 List<Header> result = new ArrayList<>(); 39 for (Map<String, String> inputHeader : headers) { 40 Map.Entry<String, String> entry = inputHeader.entrySet().iterator().next(); 41 result.add(new Header(entry.getKey(), entry.getValue())); 42 } 43 return result; 44 } 45 getWire()46 public ByteString getWire() { 47 return ByteString.decodeHex(wire); 48 } 49 getSeqno()50 public int getSeqno() { 51 return seqno; 52 } 53 setWire(ByteString wire)54 public void setWire(ByteString wire) { 55 this.wire = wire.hex(); 56 } 57 58 @Override clone()59 protected Case clone() throws CloneNotSupportedException { 60 Case result = new Case(); 61 result.seqno = seqno; 62 result.wire = wire; 63 result.headers = new ArrayList<>(); 64 for (Map<String, String> header : headers) { 65 result.headers.add(new LinkedHashMap<String, String>(header)); 66 } 67 return result; 68 } 69 } 70