Path: blob/master/test/hotspot/jtreg/serviceability/jdwp/JdwpReply.java
41152 views
/*1* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.io.ByteArrayInputStream;24import java.io.DataInputStream;25import java.io.IOException;26import java.io.InputStream;2728/**29* Generic JDWP reply30*/31public abstract class JdwpReply {3233protected final static int HEADER_LEN = 11;34private byte[] errCode = new byte[2];35private byte[] data;3637public final void initFromStream(InputStream is) throws IOException {38DataInputStream ds = new DataInputStream(is);3940int length = ds.readInt();41int id = ds.readInt();42byte flags = (byte) ds.read();4344ds.read(errCode, 0, 2);4546int dataLength = length - HEADER_LEN;47if (dataLength > 0) {48data = new byte[dataLength];49int bytesRead = ds.read(data, 0, dataLength);50// For large data JDWP agent sends two packets: 1011 bytes in51// the first packet (1000 + HEADER_LEN) and the rest in the52// second packet.53if (bytesRead > 0 && bytesRead < dataLength) {54System.out.println("[" + getClass().getName() + "] Only " +55bytesRead + " bytes of " + dataLength + " were " +56"read in the first packet. Reading the rest...");57ds.read(data, bytesRead, dataLength - bytesRead);58}5960parseData(new DataInputStream(new ByteArrayInputStream(data)));61}62}6364protected void parseData(DataInputStream ds) throws IOException {65}6667protected byte[] readJdwpString(DataInputStream ds) throws IOException {68byte[] str = null;69int len = ds.readInt();70if (len > 0) {71str = new byte[len];72ds.read(str, 0, len);73}74return str;75}7677protected long readRefId(DataInputStream ds) throws IOException {78return ds.readLong();79}8081public int getErrorCode() {82return (((errCode[0] & 0xFF) << 8) | (errCode[1] & 0xFF));83}84}858687