Exemplo n.º 1
0
  /**
   * Return a string suitable for determining file type based on extension May or may not be a full,
   * readable path. txt and gz extensions are stripped
   *
   * @return
   */
  public String getTypeString() {
    if (type != null) {
      return type;
    } else {

      String typeString = path.toLowerCase();
      if (path.startsWith("http://") || path.startsWith("https://")) {
        try {
          URL url = new URL(path);

          typeString = url.getPath().toLowerCase();
          String query = url.getQuery();
          if (query != null) {
            Map<String, String> queryMap = HttpUtils.parseQueryString(query);
            // If type is set explicitly use it
            if (queryMap.containsKey("dataformat")) {
              String format = queryMap.get("dataformat");
              if (format.contains("genomespace")) {
                typeString = GSUtils.parseDataFormatString(format);
              } else {
                typeString = format;
              }
            } else if (queryMap.containsKey("file")) {
              typeString = queryMap.get("file");
            }
          }

        } catch (MalformedURLException e) {
          log.error("Error interpreting url: " + path, e);
          typeString = path;
        }
      }

      // Strip .txt, .gz, and .xls extensions.  (So  foo.cn.gz => a .cn file)
      if ((typeString.endsWith(".txt")
          || typeString.endsWith(".xls")
          || typeString.endsWith(".gz")
          || typeString.endsWith(".bgz"))) {
        typeString = typeString.substring(0, typeString.lastIndexOf(".")).trim();
      }

      return typeString;
    }
  }
Exemplo n.º 2
0
 public static String getGSToken() {
   if (gsToken == null && !Globals.isTesting()) {
     File file = GSUtils.getTokenFile();
     if (file.exists()) {
       BufferedReader br = null;
       try {
         br = new BufferedReader(new FileReader(file));
         gsToken = br.readLine();
       } catch (IOException e) {
         log.error("Error reading GS cookie", e);
       } finally {
         if (br != null)
           try {
             br.close();
           } catch (IOException e) {
             // Ignore
           }
       }
     }
   }
   return gsToken;
 }