Source:
<code>public void run() { if (!ensureMeasurementNecessary()) return; final String sixRandomDigits = String.valueOf(mRandom.nextInt(900000) + 100000); final byte[] dnsPacket = getDnsQueryPacket(sixRandomDigits); try (SSLSocket sslSocket = setupSSLSocket()) { mMeasurement.startTime = now(); sslSocket.connect( new InetSocketAddress(mTarget, DNS_TLS_PORT), TCP_CONNECT_TIMEOUT); sslSocket.startHandshake(); maybeDoHostnameVerification(sslSocket); <START> mMeasurement.description += " src{" + getLocalAddressString(sslSocket) + "}" + " qtype{" + mQueryType + "}" + " qname{" + sixRandomDigits + "-android-ds.metric.gstatic.com}"; <END> final OutputStream output = sslSocket.getOutputStream(); final ByteBuffer querySize = ByteBuffer.allocate(2); querySize.putShort((short) dnsPacket.length); output.write(querySize.array()); output.write(dnsPacket); final InputStream input = sslSocket.getInputStream(); final byte[] buf = new byte[2]; input.read(buf, 0, 2); final short expectReplyLen = ByteBuffer.wrap(buf).getShort(); final byte[] reply = new byte[expectReplyLen]; int read = 0; while (read < expectReplyLen) { int n = input.read(reply, read, expectReplyLen - read); if (n < 0) break; read += n; } if (read == expectReplyLen && read > DNS_HEADER_SIZE) { mMeasurement.recordSuccess("1/1 " + responseCodeStr((int) (reply[3]) & 0x0f)); } else { mMeasurement.recordFailure("Unexpected answer length " + read); } } catch (IOException | NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) { mMeasurement.recordFailure(e.toString()); } }</code><technical_language>refactor this getMeanSurementDescrption() something? Line 756 Line 768 duplicated code in DnsUdpCheck.run()</technical_language>

Target:
public void run() { if (isFailedDuringConstruction()) return; final String sixRandomDigits = String.valueOf(mRandom.nextInt(900000) + 100000); final byte[] dnsPacket = getDnsQueryPacket(sixRandomDigits); try (SSLSocket sslSocket = setupSSLSocket()) { mMeasurement.startTime = now(); sslSocket.connect( new InetSocketAddress(mTarget, DNS_TLS_PORT), TCP_CONNECT_TIMEOUT_MS); sslSocket.startHandshake(); appendDnsToMeasurementDescription( sixRandomDigits, sslSocket.getLocalSocketAddress()); final OutputStream output = sslSocket.getOutputStream(); final ByteBuffer querySize = ByteBuffer.allocate(2); querySize.putShort((short) dnsPacket.length); output.write(querySize.array()); output.write(dnsPacket); final InputStream input = sslSocket.getInputStream(); final byte[] lengthField = new byte[2]; input.read(lengthField, 0, 2); final short expectReplyLen = ByteBuffer.wrap(lengthField).getShort(); if (expectReplyLen <= 0) { throw new IOException("Unexpected length Field " + expectReplyLen); } final byte[] reply = new byte[expectReplyLen]; int read = 0; while (read < expectReplyLen) { int n = input.read(reply, read, expectReplyLen - read); if (n < 0) { throw new IOException("Unexpected EOF"); } read += n; } if (read == expectReplyLen && read > DNS_HEADER_SIZE) { mMeasurement.recordSuccess("1/1 " + responseCodeStr((int) (reply[3]) & 0x0f)); } else { mMeasurement.recordFailure( "Read " + read + " bytes while length field is " + expectReplyLen); } } catch (IOException e) { mMeasurement.recordFailure(e.toString()); } }