public String readResponse(HttpResponse response) {
    String output = "";

    HttpEntity entity = response.getEntity();

    try {
      trapException(response.getStatusLine().getStatusCode());
    } catch (CrowdFlowerException e1) {
      e1.printStackTrace();
    }

    InputStream instream;
    try {
      instream = entity.getContent();
      BufferedReader reader = new BufferedReader(new InputStreamReader(instream));

      // do something useful with the response
      output = output + reader.readLine();
      instream.close();
    } catch (IllegalStateException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }

    return output;
  }
Exemple #2
0
 private void create() {
   try {
     Messaging.log("Creating file: " + this.file.getName());
     Files.createParentDirs(this.file);
     this.file.createNewFile();
   } catch (IOException ex) {
     Messaging.severe("Could not create file: " + this.file.getName());
     ex.printStackTrace();
   }
 }
Exemple #3
0
 @Override
 public boolean load() {
   NBTInputStream stream = null;
   try {
     stream = new NBTInputStream(new GZIPInputStream(new FileInputStream(this.file)));
     final Tag tag = stream.readTag();
     if (tag == null || !(tag instanceof CompoundTag)) {
       return false;
     }
     this.root.clear();
     this.root.putAll(((CompoundTag) tag).getValue());
   } catch (IOException ex) {
     ex.printStackTrace();
     return false;
   } finally {
     try {
       stream.close();
     } catch (IOException ex2) {
     }
   }
   return true;
 }
Exemple #4
0
 @Override
 public void save() {
   NBTOutputStream stream = null;
   try {
     Files.createParentDirs(this.file);
     final File temporaryFile =
         File.createTempFile(this.file.getName(), null, this.file.getParentFile());
     temporaryFile.deleteOnExit();
     stream = new NBTOutputStream(new FileOutputStream(temporaryFile));
     stream.writeTag(new CompoundTag(this.name, this.root));
     stream.close();
     this.file.delete();
     temporaryFile.renameTo(this.file);
     temporaryFile.delete();
   } catch (IOException ex) {
     ex.printStackTrace();
   } finally {
     try {
       stream.close();
     } catch (IOException ex2) {
     }
   }
 }
  public String urlReader(URL crowdFlower) {
    String jsonInput = "";

    try {
      URLConnection yc = crowdFlower.openConnection();
      BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
      String inputLine;

      while ((inputLine = in.readLine()) != null) {
        jsonInput = jsonInput + inputLine;
      }

      in.close();

      trapException(jsonInput);

    } catch (IOException e) {
      e.printStackTrace();
    } catch (CrowdFlowerException e) {
      e.printStackTrace();
    }

    return jsonInput;
  }