Esempio n. 1
0
  /* Returns true if the message could be rendered. */
  private boolean toWire(DNSOutput out, int maxLength) {
    if (maxLength < Header.LENGTH) return false;

    Header newheader = null;

    int tempMaxLength = maxLength;
    if (tsigkey != null) tempMaxLength -= tsigkey.recordLength();

    int startpos = out.current();
    header.toWire(out);
    Compression c = new Compression();
    for (int i = 0; i < 4; i++) {
      int skipped;
      if (sections[i] == null) continue;
      skipped = sectionToWire(out, i, c, tempMaxLength);
      if (skipped != 0) {
        if (i != Section.ADDITIONAL) {
          if (newheader == null) newheader = (Header) header.clone();
          newheader.setFlag(Flags.TC);
          int count = newheader.getCount(i);
          newheader.setCount(i, count - skipped);
          for (int j = i + 1; j < 4; j++) newheader.setCount(j, 0);

          out.save();
          out.jump(startpos);
          newheader.toWire(out);
          out.restore();
        }
        break;
      }
    }

    if (tsigkey != null) {
      TSIGRecord tsigrec = tsigkey.generate(this, out.toByteArray(), tsigerror, querytsig);

      if (newheader == null) newheader = (Header) header.clone();
      tsigrec.toWire(out, Section.ADDITIONAL, c);
      newheader.incCount(Section.ADDITIONAL);

      out.save();
      out.jump(startpos);
      newheader.toWire(out);
      out.restore();
    }

    return true;
  }
Esempio n. 2
0
 /**
  * Creates a copy of this Message. This is done by the Resolver before adding TSIG and OPT
  * records, for example.
  *
  * @see Resolver
  * @see TSIGRecord
  * @see OPTRecord
  */
 public Object clone() {
   Message m = new Message();
   for (int i = 0; i < sections.length; i++) {
     if (sections[i] != null) m.sections[i] = new LinkedList(sections[i]);
   }
   m.header = (Header) header.clone();
   m.size = size;
   return m;
 }
  /**
   * Creates an instance of the <code>HttpURLConnection</code>
   *
   * @param url URL The URL this connection is connecting
   * @param port int The default connection port
   */
  protected HttpURLConnectionImpl(URL url, int port) {
    super(url);
    defaultPort = port;
    reqHeader = (Header) defaultReqHeader.clone();

    try {
      uri = url.toURI();
    } catch (URISyntaxException e) {
      // do nothing.
    }
    responseCache =
        AccessController.doPrivileged(
            new PrivilegedAction<ResponseCache>() {
              public ResponseCache run() {
                return ResponseCache.getDefault();
              }
            });
  }