Пример #1
0
 public void onError_async(
     String errcode,
     String errmsg,
     ITerminal_AsyncCallBack async,
     HashMap<String, String> props,
     Object cookie)
     throws RpcException {
   boolean r_7 = false;
   RpcMessage m_8 = new RpcMessage(RpcMessage.CALL | RpcMessage.ASYNC);
   m_8.ifidx = 0;
   m_8.opidx = 2;
   m_8.paramsize = 2;
   m_8.extra.setProperties(props);
   m_8.cookie = cookie;
   try {
     ByteArrayOutputStream bos_9 = new ByteArrayOutputStream();
     DataOutputStream dos_10 = new DataOutputStream(bos_9);
     byte[] sb_11 = errcode.getBytes();
     dos_10.writeInt(sb_11.length);
     dos_10.write(sb_11, 0, sb_11.length);
     byte[] sb_12 = errmsg.getBytes();
     dos_10.writeInt(sb_12.length);
     dos_10.write(sb_12, 0, sb_12.length);
     m_8.paramstream = bos_9.toByteArray();
     m_8.prx = this;
     m_8.async = async;
   } catch (Exception e) {
     throw new RpcException(RpcConsts.RPCERROR_DATADIRTY, e.toString());
   }
   r_7 = this.conn.sendMessage(m_8);
   if (!r_7) {
     throw new RpcException(RpcConsts.RPCERROR_SENDFAILED);
   }
 }
Пример #2
0
 public static void main(String[] args) throws IOException, NoSuchAlgorithmException {
   DataOutputStream output = new DataOutputStream(new BufferedOutputStream(System.out));
   LRC lrc = new LRC(output);
   DataInputStream input = new DataInputStream(new BufferedInputStream(System.in));
   lrc.writeStream(input);
   output.flush();
 }
Пример #3
0
  public static void testWriteView() throws Exception {
    List<Address> members = new ArrayList<>();
    View v;
    Address a1 = Util.createRandomAddress();
    Address a2 = Util.createRandomAddress();
    Address a4 = Util.createRandomAddress();
    ViewId vid = new ViewId(a1, 12345);
    members.add(a1);
    members.add(a2);
    members.add(a4);
    v = new View(vid, members);

    ByteArrayOutputStream outstream = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(outstream);
    Util.writeGenericStreamable(v, dos);
    Util.writeStreamable(v, dos);
    dos.close();
    byte[] buf = outstream.toByteArray();
    ByteArrayInputStream instream = new ByteArrayInputStream(buf);
    DataInputStream dis = new DataInputStream(instream);
    View v2 = (View) Util.readGenericStreamable(dis);
    Assert.assertEquals(v, v2);
    v2 = (View) Util.readStreamable(View.class, dis);
    Assert.assertEquals(v, v2);
  }
Пример #4
0
  public static void main(String argv[]) throws IOException {
    int i, predict_probability = 0;

    // parse options
    for (i = 0; i < argv.length; i++) {
      if (argv[i].charAt(0) != '-') break;
      ++i;
      switch (argv[i - 1].charAt(1)) {
        case 'b':
          predict_probability = atoi(argv[i]);
          break;
        default:
          System.err.print("unknown option\n");
          exit_with_help();
      }
    }
    if (i >= argv.length) exit_with_help();
    try {
      BufferedReader input = new BufferedReader(new FileReader(argv[i]));
      DataOutputStream output = new DataOutputStream(new FileOutputStream(argv[i + 2]));
      svm_model model = svm.svm_load_model(argv[i + 1]);
      if (predict_probability == 1)
        if (svm.svm_check_probability_model(model) == 0) {
          System.err.print("Model does not support probabiliy estimates\n");
          System.exit(1);
        }
      predict(input, output, model, predict_probability);
      input.close();
      output.close();
    } catch (FileNotFoundException e) {
      exit_with_help();
    } catch (ArrayIndexOutOfBoundsException e) {
      exit_with_help();
    }
  }
Пример #5
0
  /** Internal method. Connect to searchd and exchange versions. */
  private Socket _Connect() {
    if (_socket != null) return _socket;

    _connerror = false;
    Socket sock = null;
    try {
      sock = new Socket();
      sock.setSoTimeout(_timeout);
      InetSocketAddress addr = new InetSocketAddress(_host, _port);
      sock.connect(addr, _timeout);

      DataInputStream sIn = new DataInputStream(sock.getInputStream());
      int version = sIn.readInt();
      if (version < 1) {
        sock.close();
        _error = "expected searchd protocol version 1+, got version " + version;
        return null;
      }

      DataOutputStream sOut = new DataOutputStream(sock.getOutputStream());
      sOut.writeInt(VER_MAJOR_PROTO);

    } catch (IOException e) {
      _error = "connection to " + _host + ":" + _port + " failed: " + e;
      _connerror = true;

      try {
        if (sock != null) sock.close();
      } catch (IOException e1) {
      }
      return null;
    }

    return sock;
  }
Пример #6
0
 public void onError_oneway(String errcode, String errmsg, HashMap<String, String> props)
     throws RpcException {
   boolean r_1 = false;
   RpcMessage m_2 = new RpcMessage(RpcMessage.CALL | RpcMessage.ONEWAY);
   m_2.ifidx = 0;
   m_2.opidx = 2;
   m_2.paramsize = 2;
   m_2.extra.setProperties(props);
   try {
     ByteArrayOutputStream bos_3 = new ByteArrayOutputStream();
     DataOutputStream dos_4 = new DataOutputStream(bos_3);
     byte[] sb_5 = errcode.getBytes();
     dos_4.writeInt(sb_5.length);
     dos_4.write(sb_5, 0, sb_5.length);
     byte[] sb_6 = errmsg.getBytes();
     dos_4.writeInt(sb_6.length);
     dos_4.write(sb_6, 0, sb_6.length);
     m_2.paramstream = bos_3.toByteArray();
     m_2.prx = this;
   } catch (Exception e) {
     throw new RpcException(RpcConsts.RPCERROR_DATADIRTY, e.toString());
   }
   r_1 = this.conn.sendMessage(m_2);
   if (!r_1) {
     throw new RpcException(RpcConsts.RPCERROR_SENDFAILED);
   }
 }
Пример #7
0
  private void func_22181_a(
      File file, ArrayList arraylist, int i, int j, IProgressUpdate iprogressupdate) {
    Collections.sort(arraylist);
    byte abyte0[] = new byte[4096];
    int i1;
    for (Iterator iterator = arraylist.iterator();
        iterator.hasNext();
        iprogressupdate.setLoadingProgress(i1)) {
      ChunkFile chunkfile = (ChunkFile) iterator.next();
      int k = chunkfile.func_22323_b();
      int l = chunkfile.func_22321_c();
      RegionFile regionfile = RegionFileCache.func_22193_a(file, k, l);
      if (!regionfile.func_22202_c(k & 0x1f, l & 0x1f)) {
        try {
          DataInputStream datainputstream =
              new DataInputStream(
                  new GZIPInputStream(new FileInputStream(chunkfile.func_22324_a())));
          DataOutputStream dataoutputstream =
              regionfile.getChunkDataOutputStream(k & 0x1f, l & 0x1f);
          for (int j1 = 0; (j1 = datainputstream.read(abyte0)) != -1; ) {
            dataoutputstream.write(abyte0, 0, j1);
          }

          dataoutputstream.close();
          datainputstream.close();
        } catch (IOException ioexception) {
          ioexception.printStackTrace();
        }
      }
      i++;
      i1 = (int) Math.round((100D * (double) i) / (double) j);
    }

    RegionFileCache.func_22192_a();
  }
Пример #8
0
  /** Internal method. Connect to searchd, send request, get response as DataInputStream. */
  private DataInputStream _DoRequest(int command, int version, ByteArrayOutputStream req) {
    /* connect */
    Socket sock = _Connect();
    if (sock == null) return null;

    /* send request */
    byte[] reqBytes = req.toByteArray();
    try {
      DataOutputStream sockDS = new DataOutputStream(sock.getOutputStream());
      sockDS.writeShort(command);
      sockDS.writeShort(version);
      sockDS.writeInt(reqBytes.length);
      sockDS.write(reqBytes);

    } catch (Exception e) {
      _error = "network error: " + e;
      _connerror = true;
      return null;
    }

    /* get response */
    byte[] response = _GetResponse(sock);
    if (response == null) return null;

    /* spawn that tampon */
    return new DataInputStream(new ByteArrayInputStream(response));
  }
Пример #9
0
 // write out the haar SPIHT results
 public static void WriteImage(String File_name, int imgsize) throws IOException {
   DataOutputStream out = new DataOutputStream(new FileOutputStream(File_name));
   for (int i = 0; i < imgsize; i++)
     for (int j = 0; j < imgsize; j++) out.writeInt(OriginImage[i][j]);
   // out.writeByte(OriginImage[i][j]);
   out.close();
 }
Пример #10
0
  public void marshal(DataOutputStream dos) {
    super.marshal(dos);
    try {
      minefieldID.marshal(dos);
      requestingEntityID.marshal(dos);
      dos.writeByte((byte) requestID);
      dos.writeByte((byte) requestedPerimeterPoints.size());
      dos.writeByte((byte) pad2);
      dos.writeByte((byte) sensorTypes.size());
      dos.writeInt((int) dataFilter);
      requestedMineType.marshal(dos);

      for (int idx = 0; idx < requestedPerimeterPoints.size(); idx++) {
        Point aPoint = requestedPerimeterPoints.get(idx);
        aPoint.marshal(dos);
      } // end of list marshalling

      for (int idx = 0; idx < sensorTypes.size(); idx++) {
        TwoByteChunk aTwoByteChunk = sensorTypes.get(idx);
        aTwoByteChunk.marshal(dos);
      } // end of list marshalling

    } // end try
    catch (Exception e) {
      System.out.println(e);
    }
  } // end of marshal method
Пример #11
0
 /**
  * Writes this <code>State</code> to the given output stream.
  *
  * @param dos the data output stream
  * @throws IOException if an error occurs
  */
 public void writeBinary(DataOutputStream dos) throws IOException {
   dos.writeInt(TYPE);
   dos.writeInt(index);
   dos.writeChar(c);
   dos.writeInt(qtrue);
   dos.writeInt(qfalse);
 }
Пример #12
0
  public static void main(String[] args) throws NumberFormatException, IOException {

    FileInputStream inFile = new FileInputStream(new File("C-small-practice.in"));
    DataInputStream in = new DataInputStream(inFile);
    FileOutputStream outFile = new FileOutputStream(new File("out.txt"));
    DataOutputStream out = new DataOutputStream(outFile);

    int cases = Integer.parseInt(in.readLine());

    t9Map = new HashMap<String, String>();
    fillMap();

    for (int i = 1; i <= cases; i++) {
      out.writeBytes("Case #" + i + ": ");
      String t9, t9last = "";

      String text = in.readLine();
      for (int j = 0; j < text.length(); j++) {

        t9 = t9Map.get(String.valueOf(text.charAt(j)));

        // do we need a break? (letters are on same button)
        if (j > 0 && (t9.charAt(0)) == t9last.charAt(0)) {
          out.writeBytes(" ");
        }

        out.writeBytes(t9);
        t9last = t9;
      }
      out.writeBytes("\n");
    }
  }
Пример #13
0
  /** Save the contents of the FS image */
  void saveFSImage(File fullimage, File edits) throws IOException {
    File curFile = new File(fullimage, FS_IMAGE);
    File newFile = new File(fullimage, NEW_FS_IMAGE);
    File oldFile = new File(fullimage, OLD_FS_IMAGE);

    //
    // Write out data
    //
    DataOutputStream out =
        new DataOutputStream(new BufferedOutputStream(new FileOutputStream(newFile)));
    try {
      out.writeInt(rootDir.numItemsInTree() - 1);
      rootDir.saveImage("", out);
    } finally {
      out.close();
    }

    //
    // Atomic move sequence
    //
    // 1.  Move cur to old
    curFile.renameTo(oldFile);

    // 2.  Move new to cur
    newFile.renameTo(curFile);

    // 3.  Remove pending-edits file (it's been integrated with newFile)
    edits.delete();

    // 4.  Delete old
    oldFile.delete();
  }
Пример #14
0
 public static void httpWrite(HttpURLConnection cx, String data)
     throws IOException, ProtocolException {
   cx.setDoOutput(true);
   DataOutputStream wr = new DataOutputStream(cx.getOutputStream());
   wr.writeBytes(data);
   wr.flush();
   wr.close();
 }
Пример #15
0
 public void save(DataOutputStream out) throws IOException {
   out.writeInt(totalFrequency);
   out.writeInt(nature.length);
   for (int i = 0; i < nature.length; ++i) {
     out.writeInt(nature[i].ordinal());
     out.writeInt(frequency[i]);
   }
 }
 public void serialize(TreeRequest request, DataOutputStream dos, int version)
     throws IOException {
   dos.writeUTF(request.sessionid);
   CompactEndpointSerializationHelper.serialize(request.endpoint, dos);
   dos.writeUTF(request.cf.left);
   dos.writeUTF(request.cf.right);
   if (version > MessagingService.VERSION_07)
     AbstractBounds.serializer().serialize(request.range, dos);
 }
Пример #17
0
 public void cutScore(String whom) {
   try {
     out88.writeUTF("减分");
     out88.flush();
     out88.writeUTF("");
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Пример #18
0
  /**
   * Generates a byte array representing the contents of this page. Used to serialize this page to
   * disk.
   *
   * <p>The invariant here is that it should be possible to pass the byte array generated by
   * getPageData to the HeapPage constructor and have it produce an identical HeapPage object.
   *
   * @see #HeapPage
   * @return A byte array correspond to the bytes of this page.
   */
  public byte[] getPageData() {
    // int len = header.length*4 + BufferPool.PAGE_SIZE;
    int len = BufferPool.PAGE_SIZE;
    ByteArrayOutputStream baos = new ByteArrayOutputStream(len);
    DataOutputStream dos = new DataOutputStream(baos);

    // create the header of the page
    try {
      dos.write(header.getHeader());
    } catch (IOException e) {
      // this really shouldn't happen
      e.printStackTrace();
    }

    // create the tuples
    for (int i = 0; i < numSlots; i++) {

      // empty slot
      if (!getSlot(i)) {
        for (int j = 0; j < td.getSize(); j++) {
          try {
            dos.writeByte(0);
          } catch (IOException e) {
            e.printStackTrace();
          }
        }
        continue;
      }

      // non-empty slot
      for (int j = 0; j < td.numFields(); j++) {
        Field f = tuples[i].getField(j);
        try {
          f.serialize(dos);
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }

    // padding
    int zerolen = BufferPool.PAGE_SIZE - numSlots * td.getSize() - header.length();
    byte[] zeroes = new byte[zerolen];
    try {
      dos.write(zeroes, 0, zerolen);
    } catch (IOException e) {
      e.printStackTrace();
    }

    try {
      dos.flush();
    } catch (IOException e) {
      e.printStackTrace();
    }

    return baos.toByteArray();
  }
Пример #19
0
 public void addScore() {
   try {
     out88.writeUTF("加分");
     out88.flush();
     out88.writeUTF("");
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Пример #20
0
 void write(ClassEnv e, CodeAttr ce, DataOutputStream out) throws IOException, jasError {
   out.writeShort(e.getCPIndex(attr));
   out.writeInt(2 + 10 * (vars.size()));
   out.writeShort(vars.size());
   for (Enumeration en = vars.elements(); en.hasMoreElements(); ) {
     LocalVarEntry lv = (LocalVarEntry) (en.nextElement());
     lv.write(e, ce, out);
   }
 }
Пример #21
0
 public void marshal(DataOutputStream dos) {
   try {
     dos.writeFloat((float) x);
     dos.writeFloat((float) y);
     dos.writeFloat((float) z);
   } // end try
   catch (Exception e) {
     System.out.println(e);
   }
 } // end of marshal method
Пример #22
0
 public void outputBinary(DataOutputStream dos) throws IOException {
   dos.writeInt(samples.size());
   for (String s : samples) {
     dos.writeUTF(s);
   }
   dos.writeInt(cols.size());
   for (Column c : cols) {
     c.outputBinary(dos);
   }
 }
Пример #23
0
 protected void write(DataOutputStream out) throws IOException {
   out.writeUTF(allocationMode.name());
   out.writeInt(length());
   out.writeUTF(dataType().name());
   if (dataType() == Type.DOUBLE) {
     for (int i = 0; i < length(); i++) out.writeDouble(getDouble(i));
   } else {
     for (int i = 0; i < length(); i++) out.writeFloat(getFloat(i));
   }
 }
Пример #24
0
  public void marshal(DataOutputStream dos) {
    super.marshal(dos);
    try {
      minefieldID.marshal(dos);
      requestingEntityID.marshal(dos);
      dos.writeShort((short) minefieldSequenceNumbeer);
      dos.writeByte((byte) requestID);
      dos.writeByte((byte) pduSequenceNumber);
      dos.writeByte((byte) numberOfPdus);
      dos.writeByte((byte) mineLocation.size());
      dos.writeByte((byte) sensorTypes.size());
      dos.writeByte((byte) pad2);
      dos.writeInt((int) dataFilter);
      mineType.marshal(dos);

      for (int idx = 0; idx < sensorTypes.size(); idx++) {
        TwoByteChunk aTwoByteChunk = sensorTypes.get(idx);
        aTwoByteChunk.marshal(dos);
      } // end of list marshalling

      dos.writeByte((byte) pad3);

      for (int idx = 0; idx < mineLocation.size(); idx++) {
        Vector3Float aVector3Float = mineLocation.get(idx);
        aVector3Float.marshal(dos);
      } // end of list marshalling

    } // end try
    catch (Exception e) {
      System.out.println(e);
    }
  } // end of marshal method
Пример #25
0
  /** Sends a GET_MBR_REQ to *all* GossipRouters, merges responses. */
  private List _getMembers(String group) {
    List ret = new LinkedList();
    Socket sock = null;
    SocketAddress destAddr;
    DataOutputStream out = null;
    DataInputStream in = null;
    IpAddress entry;
    GossipData gossip_req, gossip_rsp;
    Address mbr;

    for (int i = 0; i < gossip_servers.size(); i++) {
      entry = (IpAddress) gossip_servers.elementAt(i);
      if (entry.getIpAddress() == null || entry.getPort() == 0) {
        if (log.isErrorEnabled()) log.error("entry.host or entry.port is null");
        continue;
      }

      try {
        // sock=new Socket(entry.getIpAddress(), entry.getPort());
        sock = new Socket();
        destAddr = new InetSocketAddress(entry.getIpAddress(), entry.getPort());
        sock.connect(destAddr, SOCKET_TIMEOUT);
        out = new DataOutputStream(sock.getOutputStream());

        gossip_req = new GossipData(GossipRouter.GOSSIP_GET, group, null, null);
        // must send GossipData as fast as possible, otherwise the
        // request might be rejected
        gossip_req.writeTo(out);
        out.flush();

        in = new DataInputStream(sock.getInputStream());
        gossip_rsp = new GossipData();
        gossip_rsp.readFrom(in);
        if (gossip_rsp.mbrs != null) { // merge with ret
          for (Iterator it = gossip_rsp.mbrs.iterator(); it.hasNext(); ) {
            mbr = (Address) it.next();
            if (!ret.contains(mbr)) ret.add(mbr);
          }
        }
      } catch (Exception ex) {
        if (log.isErrorEnabled()) log.error("exception connecting to host " + entry);
      } finally {
        Util.close(out);
        Util.close(in);
        if (sock != null) {
          try {
            sock.close();
          } catch (IOException e) {
          }
        }
      }
    }

    return ret;
  }
Пример #26
0
  /** Writes the entire state of the MersenneTwister RNG to the stream */
  public void writeState(DataOutputStream stream) throws IOException {
    int len = mt.length;
    for (int x = 0; x < len; x++) stream.writeInt(mt[x]);

    len = mag01.length;
    for (int x = 0; x < len; x++) stream.writeInt(mag01[x]);

    stream.writeInt(mti);
    stream.writeDouble(__nextNextGaussian);
    stream.writeBoolean(__haveNextNextGaussian);
  }
Пример #27
0
  void send(String msg) {
    Iterator it = clients.keySet().iterator();

    while (it.hasNext()) {
      try {
        DataOutputStream out = (DataOutputStream) clients.get(it.next());
        out.writeUTF(msg);
      } catch (IOException e) {
      }
    }
  }
Пример #28
0
 /**
  * Writes this state to the given output stream.
  *
  * @param dos the data output stream
  * @throws IOException if an error occurs
  */
 public void writeBinary(DataOutputStream dos) throws IOException {
   dos.writeInt(TYPE);
   if (phoneList == null) {
     dos.writeInt(0);
   } else {
     dos.writeInt(phoneList.length);
     for (int i = 0; i < phoneList.length; i++) {
       dos.writeInt(phonemeTable.indexOf(phoneList[i]));
     }
   }
 }
Пример #29
0
 /**
  * Write string to named file.
  *
  * @param f File to write too
  * @param contenet String to write
  * @exception IOException if we fail to save our string
  */
 private void putContent(String f, String content) throws IOException {
   DataOutputStream out = null;
   try {
     out = new DataOutputStream(new FileOutputStream(new File(bundleDir, f)));
     out.writeUTF(content);
   } finally {
     if (out != null) {
       out.close();
     }
   }
 }
Пример #30
0
 public static void testWriteNullAddress() throws Exception {
   Address a1 = null;
   ByteArrayOutputStream outstream = new ByteArrayOutputStream();
   DataOutputStream dos = new DataOutputStream(outstream);
   Util.writeAddress(a1, dos);
   dos.close();
   byte[] buf = outstream.toByteArray();
   ByteArrayInputStream instream = new ByteArrayInputStream(buf);
   DataInputStream dis = new DataInputStream(instream);
   assert Util.readAddress(dis) == null;
 }