コード例 #1
0
  private String spejdPost(JsonObject jo) {
    @SuppressWarnings({"resource"})
    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpResponse resp;

    HttpPost httpPost = new HttpPost(SPEJD_SERVICE_POST);
    httpPost.addHeader("Content-Type", "application/json");

    StringEntity reqEntity = null;
    try {
      reqEntity = new StringEntity(jo.toString());
    } catch (UnsupportedEncodingException e) {
      System.out.println(e.toString());
    }

    assert reqEntity != null;

    httpPost.setEntity(reqEntity);
    try {
      resp = httpclient.execute(httpPost);
      return EntityUtils.toString(resp.getEntity());
    } catch (IOException e) {
      e.printStackTrace();
    }

    return null;
  }
コード例 #2
0
ファイル: ShowComp.java プロジェクト: vishalshar/NetMon
 public void run() {
   for (; ; ) {
     try {
       int n = sel.select();
       if (n > 0) processSelectedKeys();
       processPendingTargets();
       if (shutdown) {
         sel.close();
         return;
       }
     } catch (IOException x) {
       x.printStackTrace();
     }
   }
 }
コード例 #3
0
 public void run() {
   while (!shutdown) {
     try {
       registerTargets();
       if (selector.select() > 0) {
         processSelectedKeys();
       }
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
   try {
     selector.close();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
コード例 #4
0
 public void receiveTarget() {
   // 接收用户输入的地址,向targets队列中加入任务
   try {
     BufferedReader localReader = new BufferedReader(new InputStreamReader(System.in));
     String msg = null;
     while ((msg = localReader.readLine()) != null) {
       if (!msg.equals("bye")) {
         Target target = new Target(msg);
         addTarget(target);
       } else {
         shutdown = true;
         selector.wakeup();
         break;
       }
     }
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
コード例 #5
0
  public void registerTargets() {
    // 取出targets队列中的任务,向Selector注册连接就绪事件
    synchronized (targets) {
      while (targets.size() > 0) {
        Target target = (Target) targets.removeFirst();

        try {
          target.channel.register(selector, SelectionKey.OP_CONNECT, target);
        } catch (IOException x) {
          try {
            target.channel.close();
          } catch (IOException e) {
            e.printStackTrace();
          }
          target.failure = x;
          addFinishedTarget(target);
        }
      }
    }
  }
コード例 #6
0
ファイル: Main.java プロジェクト: hannuvisti/NTFSparser
  /** @param args */
  public static void main(String[] args) {
    FileChannel fc = null;
    RandomAccessFile raf = null;
    // StringBuilder sb;

    if (args.length != 1) {
      System.out.println("Usage: Ntfs filename");
      System.exit(1);
    }
    /*
    sb = new StringBuilder();
    int[] foo = {129,4,229,33};
    for (int b: foo) {
        sb.insert(0,String.format("%02X", b));
    }
    System.out.println(sb.toString());
    System.exit(0);
    */
    try {
      raf = new RandomAccessFile(args[0], "r");
      fc = raf.getChannel();
      Filesystem fs = new Filesystem(fc);

      fs.demo();
      // fs.displayFs();
    } catch (FileNotFoundException x) {
      System.out.println("FNF exp: " + x.getMessage());
    } catch (IOException x) {
      System.out.println("IO exp: " + x.getMessage());
    } finally {
      if (raf != null)
        try {
          raf.close();
        } catch (IOException e) {
          e.printStackTrace(); // To change body of catch statement use File | Settings | File
          // Templates.
        }
    }
  }
コード例 #7
0
ファイル: Request.java プロジェクト: lilac/scribe-java
 byte[] getByteBodyContents() {
   if (bytePayload != null) return bytePayload;
   String body = null;
   if (payload != null) {
     body = payload;
   } else if (files.isEmpty()) {
     body = URLUtils.formURLEncodeMap(bodyParams);
   } else {
     byte res[] = null;
     try {
       res = URLUtils.doFormDataEncode(bodyParams, files, boundary).toByteArray();
     } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
     return res;
   }
   try {
     return body.getBytes(getCharset());
   } catch (UnsupportedEncodingException uee) {
     throw new OAuthException("Unsupported Charset: " + getCharset(), uee);
   }
 }