Example #1
1
  /**
   * Method to find the Euler Tour based on the Hierholzer's algorithm.
   *
   * @param g : Input graph for which the tour is to be found.
   * @return : Returns a list of edges that comprises of the Euler Tour.
   */
  public static List<Edge> findEulerTour(Graph<Vertex> g) {
    Vertex start = g.verts.get(1);
    Stack<Edge> forward = new Stack<Edge>();
    Stack<Edge> backtrack = new Stack<Edge>();
    Edge e = getUnvisitedEdge(start);
    while (e != null) {
      e.visited = true;
      forward.push(e);
      e = getUnvisitedEdge(e.To);
    }

    while (!(forward.isEmpty())) {
      e = forward.pop();
      backtrack.push(e);
      e = getUnvisitedEdge(e.From);
      while (e != null) {
        e.visited = true;
        forward.push(e);
        e = getUnvisitedEdge(e.To);
      }
    }

    List<Edge> path = new LinkedList<Edge>();
    while (!backtrack.isEmpty()) {
      Edge edge = backtrack.pop();
      path.add(edge);
    }
    return path;
  }
 /**
  * This is for debug only: print out training matrices in a CSV type format so that the matrices
  * can be examined in a spreadsheet program for debugging purposes.
  */
 private void WriteCSVfile(
     List<String> rowNames, List<String> colNames, float[][] buf, String fileName) {
   p("tagList.size()=" + tagList.size());
   try {
     FileWriter fw = new FileWriter(fileName + ".txt");
     PrintWriter bw = new PrintWriter(new BufferedWriter(fw));
     // write the first title row:
     StringBuffer sb = new StringBuffer(500);
     for (int i = 0, size = colNames.size(); i < size; i++) {
       sb.append("," + colNames.get(i));
     }
     bw.println(sb.toString());
     // loop on remaining rows:
     for (int i = 0, size = buf.length; i < size; i++) {
       sb.delete(0, sb.length());
       sb.append(rowNames.get(i));
       for (int j = 0, size2 = buf[i].length; j < size2; j++) {
         sb.append("," + buf[i][j]);
       }
       bw.println(sb.toString());
     }
     bw.close();
   } catch (IOException ioe) {
     ioe.printStackTrace();
   }
 }
 @NotNull
 public static char[] adaptiveLoadText(@NotNull Reader reader) throws IOException {
   char[] chars = new char[4096];
   List<char[]> buffers = null;
   int count = 0;
   int total = 0;
   while (true) {
     int n = reader.read(chars, count, chars.length - count);
     if (n <= 0) break;
     count += n;
     if (total > 1024 * 1024 * 10) throw new FileTooBigException("File too big " + reader);
     total += n;
     if (count == chars.length) {
       if (buffers == null) {
         buffers = new ArrayList<char[]>();
       }
       buffers.add(chars);
       int newLength = Math.min(1024 * 1024, chars.length * 2);
       chars = new char[newLength];
       count = 0;
     }
   }
   char[] result = new char[total];
   if (buffers != null) {
     for (char[] buffer : buffers) {
       System.arraycopy(buffer, 0, result, result.length - total, buffer.length);
       total -= buffer.length;
     }
   }
   System.arraycopy(chars, 0, result, result.length - total, total);
   return result;
 }
Example #4
1
 /** Return the list of ProgramElementDoc objects as Array. */
 public static ProgramElementDoc[] toProgramElementDocArray(List list) {
   ProgramElementDoc[] pgmarr = new ProgramElementDoc[list.size()];
   for (int i = 0; i < list.size(); i++) {
     pgmarr[i] = (ProgramElementDoc) (list.get(i));
   }
   return pgmarr;
 }
  public static IdeaPluginDescriptorImpl[] loadDescriptors(@Nullable StartupProgress progress) {
    if (ClassUtilCore.isLoadingOfExternalPluginsDisabled()) {
      return IdeaPluginDescriptorImpl.EMPTY_ARRAY;
    }

    final List<IdeaPluginDescriptorImpl> result = new ArrayList<IdeaPluginDescriptorImpl>();

    int pluginsCount =
        countPlugins(PathManager.getPluginsPath())
            + countPlugins(PathManager.getPreinstalledPluginsPath());
    loadDescriptors(PathManager.getPluginsPath(), result, progress, pluginsCount);
    Application application = ApplicationManager.getApplication();
    boolean fromSources = false;
    if (application == null || !application.isUnitTestMode()) {
      int size = result.size();
      loadDescriptors(PathManager.getPreinstalledPluginsPath(), result, progress, pluginsCount);
      fromSources = size == result.size();
    }

    loadDescriptorsFromProperty(result);

    loadDescriptorsFromClassPath(result, fromSources ? progress : null);

    IdeaPluginDescriptorImpl[] pluginDescriptors =
        result.toArray(new IdeaPluginDescriptorImpl[result.size()]);
    try {
      Arrays.sort(pluginDescriptors, new PluginDescriptorComparator(pluginDescriptors));
    } catch (Exception e) {
      prepareLoadingPluginsErrorMessage(
          IdeBundle.message("error.plugins.were.not.loaded", e.getMessage()));
      getLogger().info(e);
      return findCorePlugin(pluginDescriptors);
    }
    return pluginDescriptors;
  }
Example #6
1
 /**
  * Given a string, return an array of tokens. The separator can be escaped with the '\' character.
  * The '\' character may also be escaped by the '\' character.
  *
  * @param s the string to tokenize.
  * @param separator the separator char.
  * @param maxTokens the maxmimum number of tokens returned. If the max is reached, the remaining
  *     part of s is appended to the end of the last token.
  * @return an array of tokens.
  */
 public static String[] tokenize(String s, char separator, int maxTokens) {
   List tokens = new ArrayList();
   StringBuilder token = new StringBuilder();
   boolean prevIsEscapeChar = false;
   for (int i = 0; i < s.length(); i += Character.charCount(i)) {
     int currentChar = s.codePointAt(i);
     if (prevIsEscapeChar) {
       // Case 1:  escaped character
       token.appendCodePoint(currentChar);
       prevIsEscapeChar = false;
     } else if (currentChar == separator && tokens.size() < maxTokens - 1) {
       // Case 2:  separator
       tokens.add(token.toString());
       token = new StringBuilder();
     } else if (currentChar == '\\') {
       // Case 3:  escape character
       prevIsEscapeChar = true;
     } else {
       // Case 4:  regular character
       token.appendCodePoint(currentChar);
     }
   }
   if (token.length() > 0) {
     tokens.add(token.toString());
   }
   return (String[]) tokens.toArray(new String[] {});
 }
 /**
  * @return hash code of the instance
  * @author Klaus Meffert
  * @since 2.3
  */
 public int hashCode() {
   if (m_data.size() == 0) {
     return -29;
   } else {
     return m_data.hashCode();
   }
 }
  private Tree getTreeFromXML(Node root) {
    final Element eRoot = (Element) root;

    if (isWordNode(eRoot)) {
      return buildWordNode(eRoot);
    } else if (isEllipticNode(eRoot)) {
      return buildEllipticNode(eRoot);
    } else {
      List<Tree> kids = new ArrayList<>();
      for (Node childNode = eRoot.getFirstChild();
          childNode != null;
          childNode = childNode.getNextSibling()) {
        if (childNode.getNodeType() != Node.ELEMENT_NODE) continue;

        Tree t = getTreeFromXML(childNode);
        if (t == null) {
          System.err.printf(
              "%s: Discarding empty tree (root: %s)%n",
              this.getClass().getName(), childNode.getNodeName());
        } else {
          kids.add(t);
        }
      }

      return (kids.size() == 0) ? null : buildConstituentNode(eRoot, kids);
    }
  }
 @NotNull
 public static IpnbFile parseIpnbFile(
     @NotNull final CharSequence fileText, @NotNull final VirtualFile virtualFile)
     throws IOException {
   final String path = virtualFile.getPath();
   IpnbFileRaw rawFile = gson.fromJson(fileText.toString(), IpnbFileRaw.class);
   if (rawFile == null) {
     int nbformat = isIpythonNewFormat(virtualFile) ? 4 : 3;
     return new IpnbFile(Collections.emptyMap(), nbformat, Lists.newArrayList(), path);
   }
   List<IpnbCell> cells = new ArrayList<IpnbCell>();
   final IpnbWorksheet[] worksheets = rawFile.worksheets;
   if (worksheets == null) {
     for (IpnbCellRaw rawCell : rawFile.cells) {
       cells.add(rawCell.createCell());
     }
   } else {
     for (IpnbWorksheet worksheet : worksheets) {
       final List<IpnbCellRaw> rawCells = worksheet.cells;
       for (IpnbCellRaw rawCell : rawCells) {
         cells.add(rawCell.createCell());
       }
     }
   }
   return new IpnbFile(rawFile.metadata, rawFile.nbformat, cells, path);
 }
  public TreeNode[] findNodeInContext(String startCtxPath, @Nullable final String name) {
    final List<TreeNode> out = new ArrayList<TreeNode>();
    root.iterateThruContext(
        startCtxPath,
        new TreeNodeRoot.TreeNodeHandler2() {
          public boolean handleNode(int ctxPathCounter, TreeNode node) {
            if (name == null || node.getName().equalsIgnoreCase(name)) {
              out.add(node);
            }
            return true;
          }
        });

    return out.toArray(new TreeNode[out.size()]);
    /*
            String[] path = startCtxPath.split("/");
            int startWith = ("/" + path[1]).startsWith(ContextPath.FILE_CTX_PRX) ? 2 : 1;

            TreeNode cycled = root;
            for (int i = startWith; i < path.length; i++) {
                String encodedName = "/" + path[i];
                cycled = cycled.findChildByEncodedName(encodedName);
                if (cycled == null) {
                    return new TreeNode[0];
                }
            }

            return cycled.findChildrenBySuffix(name);
    */
  }
 public List<TreeNode> getChildren() {
   List<TreeNode> lst = new ArrayList<TreeNode>();
   for (List<TreeNodeImpl> lst1 : childs.values()) {
     lst.addAll(lst1);
   }
   return lst;
 }
  @NotNull
  public ContextItem[] findCtxItems(String startCtxPath, String name) {
    String[] path = startCtxPath.split("/");
    int startWith = ("/" + path[1]).startsWith(ContextPath.FILE_CTX_PRX) ? 2 : 1;

    TreeNode cycled = root;
    for (int i = startWith; i < path.length; i++) {
      String encodedName = "/" + path[i];
      cycled = cycled.findChildByEncodedName(encodedName);
      if (cycled == null) {
        return new ContextItem[0];
      }
    }

    List<ContextItem> out = new ArrayList<ContextItem>();
    TreeNode[] children =
        name == null
            ? cycled.getChildren().toArray(new TreeNode[0])
            : cycled.findChildrenBySuffix(name);
    for (TreeNode n : children) {
      // todo -- revise to replace using value directly with a TreeNode instance
      out.add(new ContextItemImpl(n.getPath(), n.getValue()));
    }

    return out.toArray(new ContextItem[out.size()]);
  }
 public static void loadDescriptors(
     String pluginsPath,
     List<IdeaPluginDescriptorImpl> result,
     @Nullable StartupProgress progress,
     int pluginsCount) {
   final File pluginsHome = new File(pluginsPath);
   final File[] files = pluginsHome.listFiles();
   if (files != null) {
     int i = result.size();
     for (File file : files) {
       final IdeaPluginDescriptorImpl descriptor = loadDescriptor(file, PLUGIN_XML);
       if (descriptor == null) continue;
       if (progress != null) {
         progress.showProgress(
             descriptor.getName(), PLUGINS_PROGRESS_MAX_VALUE * ((float) ++i / pluginsCount));
       }
       int oldIndex = result.indexOf(descriptor);
       if (oldIndex >= 0) {
         final IdeaPluginDescriptorImpl oldDescriptor = result.get(oldIndex);
         if (StringUtil.compareVersionNumbers(oldDescriptor.getVersion(), descriptor.getVersion())
             < 0) {
           result.set(oldIndex, descriptor);
         }
       } else {
         result.add(descriptor);
       }
     }
   }
 }
  private static boolean checkDependants(
      final IdeaPluginDescriptor pluginDescriptor,
      final Function<PluginId, IdeaPluginDescriptor> pluginId2Descriptor,
      final Condition<PluginId> check,
      final Set<PluginId> processed) {
    processed.add(pluginDescriptor.getPluginId());
    final PluginId[] dependentPluginIds = pluginDescriptor.getDependentPluginIds();
    final Set<PluginId> optionalDependencies =
        new HashSet<PluginId>(Arrays.asList(pluginDescriptor.getOptionalDependentPluginIds()));
    for (final PluginId dependentPluginId : dependentPluginIds) {
      if (processed.contains(dependentPluginId)) continue;

      // TODO[yole] should this condition be a parameter?
      if (isModuleDependency(dependentPluginId)
          && (ourAvailableModules.isEmpty()
              || ourAvailableModules.contains(dependentPluginId.getIdString()))) {
        continue;
      }
      if (!optionalDependencies.contains(dependentPluginId)) {
        if (!check.value(dependentPluginId)) {
          return false;
        }
        final IdeaPluginDescriptor dependantPluginDescriptor =
            pluginId2Descriptor.fun(dependentPluginId);
        if (dependantPluginDescriptor != null
            && !checkDependants(dependantPluginDescriptor, pluginId2Descriptor, check, processed)) {
          return false;
        }
      }
    }
    return true;
  }
Example #15
0
  // ---------------------------------------------------------------------------
  private void printDependencies(String target, PrintWriter pw, int spacing)
      throws TablesawException {
    Rule tr = findTargetRule(target);
    String[] pre;

    for (int I = 0; I < spacing; I++) pw.print("\t");

    List<String> targetList = new ArrayList<String>();
    if (tr != null) {
      for (String name : tr.getDependNames()) {
        targetList.add(name);
      }

      for (Rule r : tr.getDependRules()) {
        if ((r.getName() != null) && (!r.getName().startsWith(NAMED_RULE_PREFIX))) {
          targetList.add(r.getName());
        } else {
          for (String t : r.getTargets()) {
            targetList.add(t);
          }
        }
      }
    }

    if (!m_printedDependencies.add(target) && (targetList.size() != 0)) {
      pw.println(target + "*");
      return;
    }

    pw.println(target);

    for (String t : targetList) printDependencies(t, pw, spacing + 1);
  }
Example #16
0
 public static List asList(ProgramElementDoc[] members) {
   List list = new ArrayList();
   for (int i = 0; i < members.length; i++) {
     list.add(members[i]);
   }
   return list;
 }
 private List<Integer> primitiveArrayToObjectList(int[] ctxTypes) {
   List<Integer> out = new ArrayList<Integer>(ctxTypes != null ? ctxTypes.length : 0);
   for (int i = 0; i < out.size(); i++) {
     out.add(ctxTypes[i]);
   }
   return out;
 }
Example #18
0
  /**
   * This function obtains a list with the subexpressions of a given expressions
   *
   * @param expr The original expresion
   * @return the list with all the subexpressions
   */
  public static List<Expr> getListExpr(Expr expr) throws IllegalArgumentException {

    List<Expr> list = new ArrayList<Expr>();

    if (expr instanceof NumExpr) {
      list.add(expr);
    } else if (expr instanceof RefExpr) {
      RefExpr refExpr = (RefExpr) expr;
      String strRefExpr = refExpr.getZName().getWord();
      // The \emptyset expression will be ignored
      if (!strRefExpr.equals(UtilSymbols.emptySetSymbol())) list.add(expr);
    } else if (expr instanceof SetExpr) {
      list = ((SetExpr) expr).getZExprList();
    } else if (expr instanceof TupleExpr) {
      list = ((TupleExpr) expr).getZExprList();
    } else if (expr instanceof ApplExpr) {
      if (((ApplExpr) expr).getMixfix()) { // es una secuencia
        ZExprListImpl applList =
            (ZExprListImpl) ((SetExpr) (((ApplExpr) expr).getRightExpr())).getZExprList();
        for (int i = 0; i < applList.size(); i++) {
          Expr elem = (((TupleExpr) (applList.get(i))).getZExprList()).get(1);
          list.add(elem);
        }
      } else { // es un valor negativo
        list.add(expr);
      }
    } else {
      throw new IllegalArgumentException();
    }
    return list;
  }
 public IpnbCell createCell() {
   final IpnbCell cell;
   if (cell_type.equals("markdown")) {
     cell = new IpnbMarkdownCell(source, metadata);
   } else if (cell_type.equals("code")) {
     final List<IpnbOutputCell> outputCells = new ArrayList<IpnbOutputCell>();
     for (CellOutputRaw outputRaw : outputs) {
       outputCells.add(outputRaw.createOutput());
     }
     final Integer prompt = prompt_number != null ? prompt_number : execution_count;
     cell =
         new IpnbCodeCell(
             language == null ? "python" : language,
             input == null ? source : input,
             prompt,
             outputCells,
             metadata);
   } else if (cell_type.equals("raw")) {
     cell = new IpnbRawCell(source);
   } else if (cell_type.equals("heading")) {
     cell = new IpnbHeadingCell(source, level, metadata);
   } else {
     cell = null;
   }
   return cell;
 }
Example #20
0
 List<ANTLRMessage> getMessagesOfType(List<ANTLRMessage> msgs, Class c) {
   List<ANTLRMessage> filtered = new ArrayList<ANTLRMessage>();
   for (ANTLRMessage m : msgs) {
     if (m.getClass() == c) filtered.add(m);
   }
   return filtered;
 }
  public ListIterator<ICFLibAnyObj> enumerateDetails(MssCFGenContext genContext) {
    final String S_ProcName = "CFAsteriskMssCFIterateHostNodeConfFile.enumerateDetails() ";

    if (genContext == null) {
      throw CFLib.getDefaultExceptionFactory()
          .newNullArgumentException(getClass(), S_ProcName, 1, "genContext");
    }

    ICFLibAnyObj genDef = genContext.getGenDef();
    if (genDef == null) {
      throw CFLib.getDefaultExceptionFactory()
          .newNullArgumentException(getClass(), S_ProcName, 1, "genContext.getGenDef()");
    }

    List<ICFLibAnyObj> list = new LinkedList<ICFLibAnyObj>();

    if (genDef instanceof ICFAsteriskHostNodeObj) {
      Iterator<ICFAsteriskConfigurationFileObj> elements =
          ((ICFAsteriskHostNodeObj) genDef).getOptionalComponentsConfFile().iterator();
      while (elements.hasNext()) {
        list.add(elements.next());
      }
    } else {
      throw CFLib.getDefaultExceptionFactory()
          .newUnsupportedClassException(
              getClass(), S_ProcName, "genContext.getGenDef()", genDef, "ICFAsteriskHostNodeObj");
    }

    return (list.listIterator());
  }
Example #22
0
  /* hack TODO do not know how to get int status back from Windows
   * Stick in code that handles particular commands that we can figure out
   * the status.
   */
  private int determineStatus(List<String> args) {
    if (args == null) throw new NullPointerException();

    if (args.size() < 2) return 0;

    String instanceName = args.get(args.size() - 1);

    if (isCommand(args, "_delete-instance-filesystem")) {
      try {
        String dir = Paths.getInstanceDirPath(node, instanceName);
        WindowsRemoteFile instanceDir = new WindowsRemoteFile(dcomInfo.getCredentials(), dir);
        return instanceDir.exists() ? 1 : 0;
      } catch (WindowsException ex) {
        return 0;
      }
    } else if (isCommand(args, "_create-instance-filesystem")) {
      try {
        String dir = Paths.getDasPropsPath(node);
        WindowsRemoteFile dasProps = new WindowsRemoteFile(dcomInfo.getCredentials(), dir);

        if (dasProps.exists()) return 0;

        // uh-oh.  Wipe out the instance directory that was created
        dir = Paths.getInstanceDirPath(node, instanceName);
        WindowsRemoteFile instanceDir = new WindowsRemoteFile(dcomInfo.getCredentials(), dir);
        instanceDir.delete();
        return 1;
      } catch (WindowsException ex) {
        return 1;
      }
    }
    return 0;
  }
Example #23
0
 /** @see java.lang.ClassLoader#findResources(java.lang.String) */
 @Override
 public Enumeration<URL> findResources(String resourceName) throws IOException {
   String webInfResourceName = "WEB-INF/classes/" + resourceName;
   List<URL> urlList = new ArrayList<URL>();
   int jarFileListSize = jarFileList.size();
   for (int i = 0; i < jarFileListSize; i++) {
     JarFile jarFile = jarFileList.get(i);
     JarEntry jarEntry = jarFile.getJarEntry(resourceName);
     // to better support war format, look for the resourceName in the WEB-INF/classes directory
     if (loadWebInf && jarEntry == null) jarEntry = jarFile.getJarEntry(webInfResourceName);
     if (jarEntry != null) {
       try {
         String jarFileName = jarFile.getName();
         if (jarFileName.contains("\\")) jarFileName = jarFileName.replace('\\', '/');
         urlList.add(new URL("jar:file:" + jarFileName + "!/" + jarEntry));
       } catch (MalformedURLException e) {
         System.out.println(
             "Error making URL for ["
                 + resourceName
                 + "] in jar ["
                 + jarFile
                 + "] in war file ["
                 + outerFile
                 + "]: "
                 + e.toString());
       }
     }
   }
   // add all resources found in parent loader too
   Enumeration<URL> superResources = super.findResources(resourceName);
   while (superResources.hasMoreElements()) urlList.add(superResources.nextElement());
   return Collections.enumeration(urlList);
 }
Example #24
0
  /*
   * return 0 is success, otherwise failure
   */
  public final int runAdminCommandOnRemoteNode(
      Node thisNode, StringBuilder output, List<String> args, List<String> stdinLines)
      throws SSHCommandExecutionException, IllegalArgumentException, UnsupportedOperationException {

    String humanreadable = null;
    try {
      this.node = thisNode;
      dcomInfo = new DcomInfo(node);
      List<String> fullcommand = new ArrayList<String>();
      WindowsRemoteAsadmin asadmin = dcomInfo.getAsadmin();

      if (stdinLines != null && !stdinLines.isEmpty()) setupAuthTokenFile(fullcommand, stdinLines);

      fullcommand.addAll(args);
      humanreadable = dcomInfo.getNadminPath() + " " + commandListToString(fullcommand);

      // This is where the rubber meets the road...
      String out = asadmin.run(fullcommand);
      output.append(out);
      logger.info(Strings.get("remote.command.summary", humanreadable, out));
      return determineStatus(args);
    } catch (WindowsException ex) {
      throw new SSHCommandExecutionException(
          Strings.get("remote.command.error", ex.getMessage(), humanreadable), ex);
    } finally {
      teardownAuthTokenFile();
    }
  }
 public void addTypeArgument(Access node) {
   List<Access> list =
       (parent == null || state == null)
           ? getTypeArgumentListNoTransform()
           : getTypeArgumentList();
   list.addChild(node);
 }
    private long[] getTotals(int day, long start_offset) {
      if (start_offset == 0) {

        return (getTotals(day));

      } else {

        List<Long> records = getContents().get(day + "." + start_offset);

        if (records != null) {

          long[] result = new long[STAT_ENTRY_COUNT];

          if (records.size() == STAT_ENTRY_COUNT) {

            for (int i = 0; i < STAT_ENTRY_COUNT; i++) {

              result[i] = (Long) records.get(i);
            }
          }

          return (result);
        }

        return (null);
      }
    }
  /**
   * This is for book production only: print out training matrices in a Latex type format so that
   * the matrices can be inserted into my manuscript:
   *
   * <p>\begin{table}[htdp] \caption{Runtimes by Method} \centering
   *
   * <p>\begin{tabular}{|l|l|l|} \hline \textbf{Class.method name}&\textbf{Percent of total
   * runtime}&\textbf{Percent in this method}\\ \hline Chess.main&97.7&0.0\\
   * GameSearch.playGame&96.5&0.0\\
   *
   * <p>Chess.calcPieceMoves&1.7&0.8\\ \hline \end{tabular}
   *
   * <p>\label{tab:runtimes_by_method} \end{table}
   */
  private void WriteLatexFile(
      List<String> rowNames, List<String> colNames, float[][] buf, String fileName) {
    p("tagList.size()=" + tagList.size());
    int SKIP = 6;
    try {
      FileWriter fw = new FileWriter(fileName + ".latex");
      PrintWriter bw = new PrintWriter(new BufferedWriter(fw));
      int size = colNames.size() - SKIP;
      bw.print("\\begin{table*}[htdp]\n\\caption{ADD CAPTION}\\centering\\begin{tabular}{|");
      for (int i = 0; i < size + 1; i++) bw.print("l|");
      bw.println("}\n\\hline");
      bw.print(" &");
      for (int i = 0; i < size; i++) {
        bw.print("\\emph{" + colNames.get(i) + "}");
        if (i < (size - 1)) bw.print("&");
      }
      bw.println("\\\\\n\\hline");

      // bw.printf(format, args)
      // loop on remaining rows:
      for (int i = 0, size3 = buf.length - SKIP; i < size3; i++) {
        bw.print(rowNames.get(i) + "&");
        for (int j = 0, size2 = buf[i].length - SKIP; j < size2; j++) {
          bw.printf("%.2f", buf[i][j]);
          if (j < (size2 - 1)) bw.print("&");
        }
        bw.println("\\\\");
      }
      bw.println("\\hline\n\\end{tabular}\n\\label{tab:CHANGE_THIS_LABEL}\n\\end{table*}");
      bw.close();
    } catch (IOException ioe) {
      ioe.printStackTrace();
    }
  }
Example #28
0
  private CipherTest(PeerFactory peerFactory) throws IOException {
    THREADS = Integer.parseInt(System.getProperty("numThreads", "4"));
    factory = (SSLSocketFactory) SSLSocketFactory.getDefault();
    SSLSocket socket = (SSLSocket) factory.createSocket();
    String[] cipherSuites = socket.getSupportedCipherSuites();
    String[] protocols = socket.getSupportedProtocols();
    //      String[] clientAuths = {null, "RSA", "DSA"};
    String[] clientAuths = {null};
    tests =
        new ArrayList<TestParameters>(cipherSuites.length * protocols.length * clientAuths.length);
    for (int i = 0; i < cipherSuites.length; i++) {
      String cipherSuite = cipherSuites[i];

      for (int j = 0; j < protocols.length; j++) {
        String protocol = protocols[j];

        if (!peerFactory.isSupported(cipherSuite, protocol)) {
          continue;
        }

        for (int k = 0; k < clientAuths.length; k++) {
          String clientAuth = clientAuths[k];
          if ((clientAuth != null) && (cipherSuite.indexOf("DH_anon") != -1)) {
            // no client with anonymous ciphersuites
            continue;
          }
          tests.add(new TestParameters(cipherSuite, protocol, clientAuth));
        }
      }
    }
    testIterator = tests.iterator();
  }
 @NotNull
 public static byte[] adaptiveLoadBytes(@NotNull InputStream stream) throws IOException {
   byte[] bytes = new byte[4096];
   List<byte[]> buffers = null;
   int count = 0;
   int total = 0;
   while (true) {
     int n = stream.read(bytes, count, bytes.length - count);
     if (n <= 0) break;
     count += n;
     if (total > 1024 * 1024 * 10) throw new FileTooBigException("File too big " + stream);
     total += n;
     if (count == bytes.length) {
       if (buffers == null) {
         buffers = new ArrayList<byte[]>();
       }
       buffers.add(bytes);
       int newLength = Math.min(1024 * 1024, bytes.length * 2);
       bytes = new byte[newLength];
       count = 0;
     }
   }
   byte[] result = new byte[total];
   if (buffers != null) {
     for (byte[] buffer : buffers) {
       System.arraycopy(buffer, 0, result, result.length - total, buffer.length);
       total -= buffer.length;
     }
   }
   System.arraycopy(bytes, 0, result, result.length - total, total);
   return result;
 }
Example #30
0
 /**
  * Constructor for Graph
  *
  * @param size : int - number of vertices
  */
 Graph(int size) {
   numNodes = size;
   verts = new ArrayList<>(size + 1);
   verts.add(0, null);
   // create an array of Vertex objects
   for (int i = 1; i <= size; i++) verts.add(i, new Vertex(i));
 }