Esempio n. 1
0
  void ReceiveFile() throws Exception {
    String fileName;

    fileName = din.readUTF();

    if (fileName != null && !fileName.equals("NOFILE")) {
      System.out.println("Receiving File");
      File f =
          new File(
              System.getProperty("user.home")
                  + "/Desktop"
                  + "/"
                  + fileName.substring(fileName.lastIndexOf("/") + 1));
      System.out.println(f.toString());
      f.createNewFile();
      FileOutputStream fout = new FileOutputStream(f);
      int ch;
      String temp;
      do {
        temp = din.readUTF();
        ch = Integer.parseInt(temp);
        if (ch != -1) {
          fout.write(ch);
        }
      } while (ch != -1);
      System.out.println("Received File : " + fileName);
      fout.close();
    } else {
    }
  }
Esempio n. 2
0
  private static FileItem prepareFileItemFromInputStream(
      PipelineContext pipelineContext, InputStream inputStream, int scope) {
    // Get FileItem
    final FileItem fileItem = prepareFileItem(pipelineContext, scope);
    // Write to file
    OutputStream os = null;
    try {
      os = fileItem.getOutputStream();
      copyStream(inputStream, os);
    } catch (IOException e) {
      throw new OXFException(e);
    } finally {
      if (os != null) {
        try {
          os.close();
        } catch (IOException e) {
          throw new OXFException(e);
        }
      }
    }
    // Create file if it doesn't exist (necessary when the file size is 0)
    final File storeLocation = ((DiskFileItem) fileItem).getStoreLocation();
    try {
      storeLocation.createNewFile();
    } catch (IOException e) {
      throw new OXFException(e);
    }

    return fileItem;
  }
  /**
   * Запрос с указанием параметров.
   *
   * @see MoneyDownloader#login
   * @see MoneyDownloader#password
   * @see MoneyDownloader#dateStart
   * @see MoneyDownloader#dateEnd
   */
  public final void run() {
    File file = new File(directory + "/Results.tsv");
    //        File test = new File(directory + "/tmp/result.tsv");

    try {
      if (!file.exists()) {
        file.createNewFile();
      }
    } catch (IOException e) {
      e.printStackTrace();
    }

    String request = "https://rt.miran.ru?user="******"&pass="******"http://rt.miran.ru/rt/Search/Results.tsv?user="******"&pass="******"&Format=%27__Created__%2FTITLE%3A%D0%94%D0%B0%D1%82%D0%B0%27%2C%0A%27%20%20%20%3Cb%3E%3Ca%20href%3D%22%2Frt%2FTicket%2FDisplay.html%3Fid%3D__id__%22%3E__id__%3C%2Fa%3E%3C%2Fb%3E%2FTITLE%3A%23%27%2C%0A%27__Subject__%2FTITLE%3A%D0%A2%D0%B5%D0%BC%D0%B0%27%2C%0A%27__QueueName__%2FTITLE%3A%D0%9E%D1%87%D0%B5%D1%80%D0%B5%D0%B4%D1%8C%27%2C%0A%27__CustomField.%7Binteraction%20type%7D__%2FTITLE%3A%D0%A2%D0%B8%D0%BF%27%2C%0A%27__CustomField.%7Bbussines%7D__%2FTITLE%3A%D0%91%D0%B8%D0%B7%D0%BD%D0%B5%D1%81%27%2C%0A%27__CustomField.%7Bdirection%7D__%2FTITLE%3A%D0%9D%D0%B0%D0%BF%D1%80%D0%B0%D0%B2%D0%BB%D0%B5%D0%BD%D0%B8%D0%B5%27%2C%0A%27__CustomField.%7Bservice%7D__%2FTITLE%3A%D0%A3%D1%81%D0%BB%D1%83%D0%B3%D0%B0%27%2C%0A%27__CustomField.%7BSD%20Type%7D__%2FTITLE%3A%D0%9A%D0%B0%D1%82%D0%B5%D0%B3%D0%BE%D1%80%D0%B8%D1%8F%27%2C%0A%27__CustomField.%7BSD%20Detail%7D__%2FTITLE%3A%D0%91%D0%BE%D0%BD%D1%83%D1%81%27%2C%0A%27__CustomField.%7BQA%7D__%2FTITLE%3A%D0%92%D1%8B%D0%BF%D0%BE%D0%BB%D0%BD%D0%B8%D0%BB%27&Order=DESC%7CASC%7CASC%7CASC&OrderBy=Created%7C%7C%7C&Page=1&Query=Created%20%3E%20%27"
            + dateStart
            + "%27%20AND%20Created%20%3C%20%27"
            + dateEnd
            + "%27%20AND%20Status%20%3D%20%27closed%27%20AND%20Queue%20!%3D%20%27manager%27%20AND%20Queue%20!%3D%20%27sales%27%20AND%20%27CF.%7BQA%7D%27%20%3D%20%27__CurrentUser__%27&RowsPerPage=0&SavedChartSearchId=new&SavedSearchId=";

    System.out.println(tickets);

    ListCookieHandler cookieHandler = new ListCookieHandler();
    CookieHandler.setDefault(cookieHandler);
    try {
      URL url = new URL(request);

      HttpURLConnection connection = (HttpURLConnection) url.openConnection();
      connection.getResponseCode();

      GetMethod method = new GetMethod(tickets);
      method.addRequestHeader("Cookie", cookieHandler.getCookiez());
      method.addRequestHeader("Referer", "http://rt.miran.ru/");
      HttpClient httpClient = new HttpClient();

      httpClient.executeMethod(method);

      InputStream in = method.getResponseBodyAsStream();
      System.out.println(in.available());

    } catch (MalformedURLException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  /** Attempts to load the white-list. */
  private boolean loadWhiteList() {

    File whitelistFile = new File(Globals.PLUGIN_FOLDER + "/" + Globals.WHITE_LIST_FILENAME);

    if (whitelistFile.exists()) {
      BufferedReader br = null;
      try {

        // --- CR (10-14/12) --- Removed the try-with-resources block to support backwards
        // compatibility.
        // try (BufferedReader br = new BufferedReader(new FileReader(whitelistFile)))
        br = new BufferedReader(new FileReader(whitelistFile));
        if (br != null) {
          String domain;
          while ((domain = br.readLine()) != null) {
            if (domain != "") {
              this.whitelist.add(domain.toUpperCase());
            }
          }
        }

        br.close();

        return true;
      } catch (FileNotFoundException fnfe) {
      } catch (IOException io) {
      } finally {
        try {
          br.close();
        } catch (IOException io) {

        }
      }
    } else {
      // The white-list was not found so create it.
      try {
        whitelistFile.createNewFile();
      } catch (IOException io) {
        Logger.debug(
            MessageFormat.format(
                "Cannot create \"{0}/{1}\".", Globals.PLUGIN_FOLDER, Globals.WHITE_LIST_FILENAME));
      }
    }
    // END OF if(whitelistFile.exists())...

    return false;
  }
  // public static void main() throws Exception {
  public void statisticsReceiver(BufferedReader inFromClient) {
    String cpu = "";
    String hdd = "";
    String ram = "";
    String clientIP = "";
    int i;
    // int count = 0;

    // ServerSocket welcomeSocket = new ServerSocket(6789);
    //		while(true) {
    //
    //			Socket connSocket = welcomeSocket.accept();
    //			BufferedReader inFromClient = new BufferedReader(new
    // InputStreamReader(connSocket.getInputStream()));
    //			DataOutputStream outToClient = new DataOutputStream(connSocket.getOutputStream());
    try {
      clientIP = inFromClient.readLine();
      clientIP = clientIP.substring(0); // To remove the preceding slash

      cpu = inFromClient.readLine();
      hdd = inFromClient.readLine();
      ram = inFromClient.readLine();
      System.out.println(
          "Stats from " + clientIP + "\n CPU-" + cpu + "\n HDD- " + hdd + "\n RAM-" + ram);
    }
    // Writer writer = null;
    catch (Exception e) {
      // e.printStackTrace();
      System.out.println("Exception in TCPServer.java while receiving statistics.");
    }
    System.out.println("OperatingSystem.pm.length = " + OperatingSystem.pm.length);
    System.out.println("clientIP = " + clientIP);
    for (i = 0; i < OperatingSystem.pm.length; i++) {

      String temp[] = OperatingSystem.pm[i].getIp().split("@");

      if (clientIP.equalsIgnoreCase(temp[1])) {
        System.out.println("Stat values from " + clientIP + "added to queues");
        OperatingSystem.pm[i].cpuQueue.insert(Double.parseDouble(cpu));
        OperatingSystem.pm[i].hddQueue.insert(Double.parseDouble(hdd));
        OperatingSystem.pm[i].ramQueue.insert(Double.parseDouble(ram));
      }
    }

    try {
      File file = new File(clientIP);
      boolean exist = file.createNewFile();
      BufferedWriter writer;

      if (exist) {
        writer = new BufferedWriter(new FileWriter(file));
        // writer.write(cpu+"\n");
        // writer.write(hdd+"\n");
        // writer.write(ram+"\n");
        writer.write("cpu: " + cpu + " hdd: " + hdd + " ram: " + ram);
        writer.write("\n");
      } else {
        FileOutputStream fos = new FileOutputStream(clientIP, true);
        // String strContent = "Append output to a file example";
        String newline = "\n";
        String CPU = "cpu: ";
        String HDD = " hdd: ";
        String RAM = " ram: ";
        fos.write(newline.getBytes());
        // fos.write(newline.getBytes());
        // fos.write(clientIP.getBytes());
        // fos.write(newline.getBytes());
        fos.write(CPU.getBytes());
        fos.write(cpu.getBytes());
        // fos.write(newline.getBytes());
        fos.write(HDD.getBytes());
        fos.write(hdd.getBytes());
        // fos.write(newline.getBytes());
        fos.write(RAM.getBytes());
        fos.write(ram.getBytes());
        fos.write(newline.getBytes());
      }
    } catch (Exception ex) {
      // ex.printStackTrace();
      System.out.println("Exception in TCPServer.java while writing statistics.");
    }
  }
Esempio n. 6
0
 public static File makeFile(String filePath) throws IOException {
   File file = new File(filePath);
   file.getParentFile().mkdirs();
   file.createNewFile();
   return file;
 }
Esempio n. 7
0
  public static void main(String args[]) throws Exception {

    int index;

    BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
    DatagramSocket clientSocket = new DatagramSocket();

    byte[] sendData = new byte[1024];
    byte[] receiveData = new byte[1024];

    // Pull the target host from the command line.
    InetAddress ipAddress = null;
    if (args.length > 0) {
      ipAddress = InetAddress.getByName(args[0]);
    } else {
      System.err.println("FATAL: You must specify a hast to connect to.");
      System.exit(1);
    }

    // Get the request string from input and send it off.
    String request = inFromUser.readLine();
    sendData = request.getBytes();
    DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, ipAddress, PORT);
    clientSocket.send(sendPacket);

    // Get the header packet.
    DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
    clientSocket.receive(receivePacket);
    receiveData = receivePacket.getData();

    String[] words = new String[8];
    words = (new String(receiveData)).split("\\s+");

    int numBytes = Integer.parseInt(words[1]);

    boolean[] packets = new boolean[numBytes];

    File download_file = new File("downloaded_file");
    download_file.createNewFile();

    RandomAccessFile download = new RandomAccessFile(download_file, "rw");
    download.setLength(numBytes);

    clientSocket.setSoTimeout(1000);

    // Get the server's response.
    do {
      try {
        while (true) {
          receivePacket = new DatagramPacket(receiveData, receiveData.length);
          clientSocket.receive(receivePacket);
          receiveData = receivePacket.getData();

          // Convert the first two bytes back into the integer index of this packet.
          index = 256 * (receiveData[0] & 0xff) + (receiveData[1] & 0xff);
          packets[index] = true;
          download.seek(index * 1022);

          for (int i = 0; i < 1021; ++i) {
            download.writeByte(receiveData[i + 2]);
          }
        }
      } catch (Exception e) {
      }
    } while (moreToDo(packets));
  }
Esempio n. 8
0
  /**
   * Creates the java help
   *
   * @param path the path where to create the java help
   * @param lang the spoken language
   */
  private void createJavaHelp(File path, String lang) {
    File pages = new File(path, "pages");
    if (pages.exists()) deleteDir(pages);
    pages.mkdir();

    File javahelpsearch = new File(path, SEARCH_DIR);
    if (javahelpsearch.exists()) deleteDir(javahelpsearch);

    File helpset_file = new File(path, HELPSET_NAME_BASE + lang + HELPSET_NAME_SUFFIX);
    File config_file = null;
    File map_file = null;
    File tam_file = null;

    String underscore = "";

    if (helpset_file.exists()) {
      // There is a helpset corresponding to the current language
      map_file = new File(path, MAP_NAME_BASE + lang + MAP_NAME_SUFFIX);
      tam_file = new File(path, TAM_NAME_BASE + lang + TAM_NAME_SUFFIX);
      underscore = "_" + lang;
    } else {
      // There is no helpset : we use the default one
      map_file = new File(path + "Map.jhm");
      tam_file = new File(path + "TAM.xml");
    }

    config_file = new File(path, CONFIG_FILE);

    if (config_file.exists()) config_file.delete();
    if (map_file.exists()) map_file.delete();
    if (tam_file.exists()) tam_file.delete();

    boolean test = true;

    try {
      // Generates the jhm and copy the file for objects
      // Generates the TAM.xml file
      test = test && map_file.createNewFile();
      test = test && tam_file.createNewFile();
      File lang_dir = new File(path, "Main_pages/" + lang);
      test = test && lang_dir.exists();
      if (test) {
        print = new PrintWriter(new BufferedWriter(new FileWriter(map_file)));
        // debut  + images
        print.println(
            "<?xml version='1.0' encoding='ISO-8859-1' ?>\n "
                + "<!DOCTYPE map\n"
                + "PUBLIC \"-//Sun Microsystems Inc.//DTD JavaHelp Map Version 1.0//EN\"\n"
                + "\"http://java.sun.com/products/javahelp/map_1_0.dtd\">\n"
                + "\n"
                + "<map version=\"1.0\">\n"
                + "<mapID target=\"image\" url=\"Main_pages/logo_cbs_petit.gif\" />\n"
                + "<mapID target=\"tamicon\" url=\"Main_pages/tam.gif\" />\n"
                + "<mapID target=\"fileicon\" url=\"Main_pages/file.gif\" />\n"
                + "<mapID target=\""
                + FIRST_PAGE
                + "\" url=\"pages/"
                + FIRST_PAGE
                + ".html\" />");

        print2 = new PrintWriter(new BufferedWriter(new FileWriter(tam_file)));
        print2.println(
            " <?xml version='1.0' encoding='ISO-8859-1'  ?> \n "
                + "<!DOCTYPE toc \n"
                + "PUBLIC \"-//Sun Microsystems Inc.//DTD JavaHelp TOC Version 2.0//EN\"\n"
                + "\"../dtd/toc_2_0.dtd\">\n"
                + "<toc version=\"2.0\"> \n<tocitem text=\""
                + getTitle(new File(path, "Main_pages/" + lang + "/" + FIRST_PAGE + ".html"))
                + "\" target=\""
                + FIRST_PAGE
                + "\" image=\"image\">");
        copyFile(
            new File(path, "Main_pages/" + lang + "/" + FIRST_PAGE + ".html"),
            new File(path, "pages/" + FIRST_PAGE + ".html"));

        // generation of the tree
        File[] list_lang_dir = lang_dir.listFiles();
        for (int a = 0; a < list_lang_dir.length; a++) {
          if (!list_lang_dir[a].getName().equals("CVS")
              && list_lang_dir[a].isFile()
              && !list_lang_dir[a].getName().equals(FIRST_PAGE + ".html")) {
            mapAndTocForFile(list_lang_dir[a], path, underscore);
          }
        }

        // Ends
        print.println("</map>");
        print.close();

        print2.println("</tocitem>\n</toc>");
        print2.close();

        test = test && config_file.createNewFile();
        if (test) {
          // Generates the config file
          print = new PrintWriter(new BufferedWriter(new FileWriter(config_file)));
          print.print("IndexRemove " + path.getAbsolutePath());
          print.close();
        }
      }
    } catch (Exception e) {
      LOG.error("Error getHelp " + e);
    }
    // Generates the search database
    String[] args =
        new String[] {
          pages.getAbsolutePath(),
          "-c",
          config_file.getAbsolutePath(),
          "-db",
          javahelpsearch.getAbsolutePath(),
          "-locale",
          lang
        };
    // Indexer indexer=new Indexer();
    // FIXME help desactived
    //		Indexer.main(args);

    Calendar c = GregorianCalendar.getInstance();
    c.setTime(new Date());
    int day = c.get(Calendar.DAY_OF_MONTH);
    int month = c.get(Calendar.MONTH) + 1;
    int year = c.get(Calendar.YEAR);
    int hour = c.get(Calendar.HOUR_OF_DAY);
    int minute = c.get(Calendar.MINUTE);
    int seconds = c.get(Calendar.SECOND);

    File log = new File(path, LOG_FILE);
    try {
      log.createNewFile();
      PrintWriter printlog = new PrintWriter(new BufferedWriter(new FileWriter(log)));
      printlog.println("Language " + lang);
      printlog.println(
          "Date : " + year + " " + month + " " + day + " " + hour + " " + minute + " " + seconds);
      printlog.close();
    } catch (Exception e) {
      LOG.error("Error while creating log " + e);
    }
  }
Esempio n. 9
0
  private void mapAndTocForFile(File f, File path, String underscore) {
    // we get the single name of the file and the urlname
    int under_index2 = f.getName().indexOf("_");
    int point_index2 = f.getName().indexOf(".");
    String named = f.getName().substring(under_index2 + 1, point_index2);
    String tmp = path.getAbsolutePath() + "Main_pages/fr/";
    String url_name = f.getPath().replace("\\", "/").substring(tmp.length());
    String targetName = url_name.substring(0, url_name.lastIndexOf(".html"));

    // now we will add into the map and the toc
    print.println("<mapID target=\"" + targetName + "\" url=\"pages/" + url_name + "\"/>");
    File dir_associated = new File(f.getParent(), named);

    if ((dir_associated.exists() && dir_associated.isDirectory()) || named.equals("objects")) {
      print2.println(
          "<tocitem text=\"" + getTitle(f) + "\" target=\"" + targetName + "\" image=\"tamicon\">");
      if (dir_associated.exists()) {
        // Apres on fait pareil pour tous les sous fichiers
        File[] sub_files = dir_associated.listFiles();
        for (int i = 0; i < sub_files.length; i++) {
          if (!sub_files[i].getName().equals("CVS") && sub_files[i].isFile()) {
            if (sub_files[i].getName().endsWith(".html"))
              mapAndTocForFile(sub_files[i], path, underscore);
            else {
              try {
                copyFile(
                    sub_files[i], new File(path, "pages/" + named + "/" + sub_files[i].getName()));
              } catch (IOException e) {
                LOG.error("Error while copying normal files in help " + e);
              }
            }
          }
        }
      }
      if (named.equals("objects")) {
        // Specialement pour les objets on les rajoute tous
        File objects_dir =
            new File(
                Configuration.instance()
                        .getTangaraPath()
                        .getParentFile()
                        .getAbsolutePath()
                        .replace("\\", "/")
                    + "/objects/");
        File[] listfiles = objects_dir.listFiles();
        Vector<String> list_names = new Vector<String>();
        HashMap<String, String> map = new HashMap<String, String>();
        for (int i = 0; i < listfiles.length; i++) {
          try {
            if (listfiles[i].getName().endsWith(".jar")) {
              int point_index = listfiles[i].getName().lastIndexOf(".");
              String name = listfiles[i].getName().substring(0, point_index);

              // Copy the pages in the right directory
              File object_dir = new File(path, "pages/" + name);
              object_dir.mkdir();
              File object_ressource =
                  new File(
                      Configuration.instance()
                              .getTangaraPath()
                              .getParentFile()
                              .getAbsolutePath()
                              .replace("\\", "/")
                          + "/objects/resources/"
                          + name
                          + "/Help");
              if (object_ressource.exists()) {
                File[] list_html_object = object_ressource.listFiles();
                for (int e = 0; e < list_html_object.length; e++) {
                  if (list_html_object[e].getName().endsWith(".html")) {
                    int under_index = list_html_object[e].getName().lastIndexOf("_");
                    if (underscore.equals("") && under_index == -1)
                      copyFile(
                          list_html_object[e],
                          new File(path, "pages/" + name + "/" + list_html_object[e].getName()));
                    else if (!underscore.equals("")) {
                      if (list_html_object[e].getName().contains(underscore))
                        copyFile(
                            list_html_object[e],
                            new File(path, "pages/" + name + "/" + list_html_object[e].getName()));
                    }
                  } else
                    copyFile(
                        list_html_object[e],
                        new File(path, "pages/" + name + "/" + list_html_object[e].getName()));
                }
                // Gets the name of the object in the selected language
                String name_lang = null;
                if (underscore.equals("")) name_lang = name;
                else {
                  name_lang = getLangName(listfiles[i]);
                }
                if (name_lang != null) {
                  list_names.add(name_lang);
                  map.put(name_lang, name);
                  // Add to the map file
                  print.println(
                      "<mapID target=\""
                          + name
                          + "\" url=\"pages/"
                          + name
                          + "/index"
                          + underscore
                          + ".html\" />");
                }
              }
            }
          } catch (Exception e2) {
            LOG.error("Error2 getHelp " + e2);
          }
        }
        // Add to the tam file
        Collections.sort(list_names);
        for (String s : list_names) {
          print2.println(
              "<tocitem text=\"" + s + "\" target=\"" + map.get(s) + "\" image=\"fileicon\" />");
        }
      }
      print2.println("</tocitem>");
    } else {
      // pas de sous fichiers
      print2.println(
          "<tocitem text=\""
              + getTitle(f)
              + "\" target=\""
              + targetName
              + "\" image=\"fileicon\"/>");
    }

    File parent = new File(path, "pages/" + url_name.substring(0, url_name.lastIndexOf(named) - 3));
    if (!parent.exists()) parent.mkdirs();
    File in_pages = new File(path, "pages/" + url_name);
    try {
      in_pages.createNewFile();
      copyFile(f, in_pages);
    } catch (IOException e3) {
      LOG.error("Error 3 getHelp " + e3 + " " + f.getName());
    }
  }
Esempio n. 10
0
  private void readData() {
    if (couldNotFetch) return;

    String test = VoxelUpdate.url;
    test = test.toLowerCase();

    if (!test.endsWith(".xml")) {
      return;
    }

    try {
      File xml = new File("plugins/VoxelUpdate/temp.xml");

      if (!xml.exists()) {
        xml.createNewFile();
      }

      BufferedInputStream bi = new BufferedInputStream(new URL(VoxelUpdate.url).openStream());
      FileOutputStream fo = new FileOutputStream(xml);
      BufferedOutputStream bo = new BufferedOutputStream(fo, 1024);
      byte[] b = new byte[1024];
      int i = 0;

      while ((i = bi.read(b, 0, 1024)) >= 0) {
        bo.write(b, 0, i);
      }

      bo.close();
      bi.close();

      DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
      DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
      Document doc = dBuilder.parse(xml);
      doc.getDocumentElement().normalize();

      Element base = doc.getDocumentElement();
      NodeList pluginList = doc.getElementsByTagName("plugin");
      xml.delete();

      for (i = 0; i < pluginList.getLength(); i++) {
        Node n = pluginList.item(i);
        String name = null;
        HashMap<String, String> _map = new HashMap<String, String>();

        if (n.getNodeType() == Node.ELEMENT_NODE) {
          Element e = (Element) n;
          String version = "";
          String url = "";
          String authors = "";
          String description = "";

          try {

            if (getTagValue("name", e) != null) {
              name = getTagValue("name", e);
            } else {
              return;
            }
            if (getTagValue("version", e) != null) {
              version = getTagValue("version", e);
            }
            if (getTagValue("url", e) != null) {
              url = getTagValue("url", e);
            }
            if (getTagValue("authors", e) != null) {
              authors = getTagValue("authors", e);
            }
            if (getTagValue("description", e) != null) {
              description = getTagValue("description", e);
            }

          } catch (NullPointerException ex) {
            continue;
          }

          if (!"".equals(version)) {
            _map.put("version", version);
          }
          if (!"".equals(url)) {
            _map.put("url", url);
          }
          if (!"".equals(authors)) {
            _map.put("authors", authors);
          }
          if (!"".equals(description)) {
            _map.put("description", description);
          }

          map.put(name, _map);
        }
      }

      lastDataFetch = System.currentTimeMillis();

    } catch (MalformedURLException e) {
      VoxelUpdate.log.severe("[VoxelUpdate] Incorrectly formatted URL to data file in preferences");
    } catch (IOException e) {
      VoxelUpdate.log.severe("[VoxelUpdate] Could not assign data to BIS");
      VoxelUpdate.log.warning(
          "[VoxelUpdate] Probably because the link is broken or the server host is down");
      VoxelUpdate.log.warning(
          "[VoxelUpdate] Also, check the properties file... It might be empty. If so, grab the default configuration (from TVB's wiki) after you stop your server, paste it into the .properties, and restart");
      VoxelUpdate.log.warning("[VoxelUpdate] ... Turning off data search until a reload...");
      couldNotFetch = true;
    } catch (ParserConfigurationException e) {
      e.printStackTrace();
    } catch (SAXException e) {
      e.printStackTrace();
    }
  }
Esempio n. 11
0
  public boolean doDownload(String plugin) {
    boolean downloaded = false;

    try {
      File dl = new File("plugins/VoxelUpdate/Downloads/" + plugin + ".jar");

      if (!dl.getParentFile().isDirectory()) {
        dl.getParentFile().mkdirs();
      }

      if (!dl.exists()) {
        dl.createNewFile();
      }

      if (get(plugin, "url") == null) {
        return false;
      }

      BufferedInputStream bi = new BufferedInputStream(new URL(get(plugin, "url")).openStream());
      FileOutputStream fo = new FileOutputStream(dl);
      BufferedOutputStream bo = new BufferedOutputStream(fo, 1024);

      byte[] b = new byte[1024];
      int i = 0;

      while ((i = bi.read(b, 0, 1024)) >= 0) {
        bo.write(b, 0, i);
      }

      bo.close();
      bi.close();

      if (VoxelUpdate.autoUpdate) {
        File dupe = new File("plugins/" + dl.getName());

        FileChannel ic = new FileInputStream(dl).getChannel();
        FileChannel oc = new FileOutputStream(dupe).getChannel();
        ic.transferTo(0, ic.size(), oc);
        ic.close();
        oc.close();

        VoxelUpdate.s
            .getPluginManager()
            .disablePlugin(VoxelUpdate.s.getPluginManager().getPlugin(plugin));

        try {
          VoxelUpdate.s
              .getPluginManager()
              .enablePlugin(VoxelUpdate.s.getPluginManager().loadPlugin(dl));
        } catch (Exception e) {
          VoxelUpdate.log.severe("[VoxelUpdate] Could not reload plugin \"" + plugin + "\"");
        }
      }

      downloaded = true;
    } catch (MalformedURLException e) {
      VoxelUpdate.log.severe(
          "[VoxelUpdate] Incorrectly formatted URL for download of \"" + plugin + "\"");
      return downloaded;
    } catch (FileNotFoundException e) {
      VoxelUpdate.log.severe("[VoxelUpdate] Could not save data to VoxelUpdate/Downloads");
      e.printStackTrace();
      return downloaded;
    } catch (IOException e) {
      VoxelUpdate.log.severe("[VoxelUpdate] Could not assign data to BIS");
      e.printStackTrace();
      return downloaded;
    }

    return downloaded;
  }