Write the tsne format

@param vec  the word vectors to use for labeling
@param tsne the tsne array to write
@param csv  the file to use
@throws Exception
976960
public static void writeTsneFormat(Glove vec, INDArray tsne, File csv) throws Exception {
        try (BufferedWriter write = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(csv), StandardCharsets.UTF_8))) {
            int words = 0;
            InMemoryLookupCache l = (InMemoryLookupCache) vec.vocab();
            for (String word : vec.vocab().words()) {
                if (word == null) {
                    continue;
                }
                StringBuilder sb = new StringBuilder();
                INDArray wordVector = tsne.getRow(l.wordFor(word).getIndex());
                for (int j = 0; j < wordVector.length(); j++) {
                    sb.append(wordVector.getDouble(j));
                    if (j < wordVector.length() - 1) {
                        sb.append(",");
                    }
                }
                sb.append(",");
                sb.append(word.replaceAll(" ", WHITESPACE_REPLACEMENT));
                sb.append(" ");

                sb.append("\n");
                write.write(sb.toString());

            }

            log.info("Wrote " + words + " with size of " + vec.lookupTable().layerSize());
        }
    }
1230009
@Override
    public void writeVectorNumber(Vector<Double> vector) {
        log.debug("writeVectorNumber: {}", vector);
        buf.put(AMF3.TYPE_VECTOR_NUMBER);
        if (hasReference(vector)) {
            putInteger(getReferenceId(vector) << 1);
            return;
        }
        storeReference(vector);
        putInteger(vector.size() << 1 | 1);
        putInteger(0);
        buf.put((byte) 0x00);
        for (Double v : vector) {
            buf.putDouble(v);
        }
    }
778124
public void writeToExcel(List<? extends Object> datas, boolean hasTitle, String path,
                             boolean transverse) throws IOException {
        writeToExcel(datas, hasTitle, path, IN_MEMORY, transverse);
    }
1083569
public static void main(String[] args) throws Exception {
    parseArgs(args);

    GenMunger rawMunger;
    rawMunger = (hex.genmodel.GenMunger) Class.forName(assemblyClassName).newInstance();

    BufferedReader input = new BufferedReader(new FileReader(inputCSVFileName));
    BufferedWriter output = new BufferedWriter(new FileWriter(outputCSVFileName));

    // Emit outputCSV column names.
    String[] rawHeader = rawMunger.outNames();
    StringBuilder header = new StringBuilder();
    for(int i=0;i<rawHeader.length;++i) {
      header.append("\"").append(rawHeader[i]).append("\"");
      if( i < rawHeader.length - 1 ) header.append(",");
    }
    output.write(header.toString());
    output.write("\n");

    // Loop over inputCSV one row at a time.
    int lineNum = 0;
    String line;
    try {
      while ((line = input.readLine()) != null) {
        lineNum++;

        // skip the header.
        if (lineNum == 1)
          continue;

        // Parse the CSV line.  Somewhat handles quoted commas.  But this ain't no parser test!
        RowData row;
        try {
          row = parseDataRow(line, rawMunger);
        } catch( NumberFormatException nfe) {
          nfe.printStackTrace();
          System.out.println("Failed to parse row: " + lineNum );
          throw new RuntimeException();
        }
        RowData mungedRow = rawMunger.fit(row);

        for(int i=0; i<rawMunger.outNames().length;++i) {
          Object val = mungedRow==null?Double.NaN:mungedRow.get(rawMunger.outNames()[i]);
          if( val instanceof Double ) output.write(String.valueOf(val));
          else                        output.write("\"" + val + "\"");
          if( i < rawMunger.outNames().length - 1) output.write(",");
        }
        output.write("\n");
      }
    }
    catch (Exception e) {
      System.out.println("Caught exception on line " + lineNum);
      System.out.println("");
      e.printStackTrace();
      System.exit(1);
    }
    finally {

      // Clean up.
      output.close();
      input.close();
    }

    // Predictions were successfully generated.  Calling program can now compare them with something.
    System.exit(0);
  }
1021588
private void setBond() throws Exception {
        List data = new Vector();
        st.nextToken();
        String scode = st.nextToken();
        String sid1 = st.nextToken();
        String sid2 = st.nextToken();
        String slen = st.nextToken();
        String sk2 = st.nextToken();
        String sk3 = st.nextToken();
        String sk4 = st.nextToken();
        String sbci = st.nextToken();

        try {
            double len = new Double(slen).doubleValue();
            double k2 = new Double(sk2).doubleValue();
            double k3 = new Double(sk3).doubleValue();
            double k4 = new Double(sk4).doubleValue();
            double bci = new Double(sbci).doubleValue();
            data.add(new Double(len));
            data.add(new Double(k2));
            data.add(new Double(k3));
            data.add(new Double(k4));
            data.add(new Double(bci));

        } catch (NumberFormatException nfe) {
            throw new IOException("setBond: Malformed Number due to:" + nfe);
        }
        //		key = "bond" + scode + ";" + sid1 + ";" + sid2;
        key = "bond" + sid1 + ";" + sid2;
        parameterSet.put(key, data);
    }
1268990
protected void writeCsvHeader(final JTable table, final Writer out, final char csvSeparator)
			throws IOException {
		// récupération des informations utiles
		final int columnCount = table.getColumnModel().getColumnCount();

		final String eol = System.getProperty("line.separator");
		if (table.getName() != null) {
			String title = formatCsv(table.getName(), csvSeparator);
			if (title.startsWith("ID")) {
				final String tmp = '"' + title + '"';
				title = tmp;
			}
			out.write(title);
			out.write(eol);
		}
		// titres des colonnes
		String text;
		for (int i = 0; i < columnCount; i++) {
			text = String.valueOf(table.getColumnModel().getColumn(i).getHeaderValue());
			text = formatCsv(text, csvSeparator);
			if (i == 0 && text.startsWith("ID")) {
				out.write('"' + text + '"'); // si commence par ID, Excel pense que c'est un sylk !
			} else {
				out.write(text);
			}
			if (i < columnCount - 1) {
				out.write(csvSeparator);
			}
		}
		out.write(eol);
	}
1118291
def write_csv(graph, prefix):
    
    node_headers = list(set([a for n, attrs in graph.nodes(data=True)
                             for a in attrs.keys()]))
    edge_headers = list(set([a for s, t, attrs in graph.edges(data=True)
                             for a in attrs.keys()]))

    value = lambda attrs, h: _recast_value(attrs[h]) if h in attrs else ''
    with open(prefix + '_nodes.csv', 'w') as f:
        writer = csv.writer(f)
        writer.writerow(['node'] + node_headers)
        for n, attrs in graph.nodes(data=True):
            values = map(value, repeat(attrs, len(node_headers)), node_headers)
            writer.writerow([_recast_value(n)] + list(values))

    with open(prefix + '_edges.csv', 'w') as f:
        writer = csv.writer(f)
        writer.writerow(['source', 'target'] + edge_headers)
        for s, t, attrs in graph.edges(data=True):
            values = map(value, repeat(attrs, len(edge_headers)), edge_headers)
            writer.writerow([_recast_value(s), _recast_value(t)] + list(values))
992866
private static byte[] writeCsv(String[] columnHeaders, String[][] rows) throws IOException {
    try (ByteArrayOutputStream csvStream = new ByteArrayOutputStream(); OutputStreamWriter streamWriter = new OutputStreamWriter(csvStream, Charset.forName("UTF-8"))) {
      CSVWriter csvWriter = new CSVWriter(streamWriter, ',');

      csvWriter.writeNext(columnHeaders);
      
      for (String[] row : rows) {
        csvWriter.writeNext(row);
      }

      csvWriter.close();
      
      return csvStream.toByteArray();
    }
  }
700282
private void writeRowsToCSV(List<String[]> rows) throws BindException
  {
    int numBytes;
    int rowNum = 0;
    int fileCount = 0;

    while (rowNum < rows.size())
    {
      File file = getFile(++fileCount);

      try (OutputStream out = openFile(file))
      {
        // until we reach the last row or the file is too big, write to the file
        numBytes = 0;
        while (numBytes < fileSize && rowNum < rows.size())
        {
          byte[] csv = createCSVRecord(rows.get(rowNum));
          numBytes += csv.length;
          out.write(csv);
          rowNum++;
        }
      }
      catch (IOException ex)
      {
        throw new BindException(
            String.format("Exception encountered while writing to file: %s", ex.getMessage()), BindException.Type.SERIALIZATION);
      }
    }
  }
1060706
@VisibleForTesting
  public static void writeCSVFile(Collection<? extends PropertyKey> defaultKeys, String filePath)
      throws IOException {
    if (defaultKeys.size() == 0) {
      return;
    }

    FileWriter fileWriter;
    Closer closer = Closer.create();
    String[] fileNames = {"user-configuration.csv", "master-configuration.csv",
        "worker-configuration.csv", "security-configuration.csv",
        "common-configuration.csv", "cluster-management-configuration.csv"};

    try {
      // HashMap for FileWriter per each category
      Map<String, FileWriter> fileWriterMap = new HashMap<>();
      for (String fileName : fileNames) {
        fileWriter = new FileWriter(PathUtils.concatPath(filePath, fileName));
        // Write the CSV file header and line separator after the header
        fileWriter.append(CSV_FILE_HEADER + "\n");
        //put fileWriter
        String key = fileName.substring(0, fileName.indexOf("configuration") - 1);
        fileWriterMap.put(key, fileWriter);
        //register file writer
        closer.register(fileWriter);
      }

      // Sort defaultKeys
      List<PropertyKey> dfkeys = new ArrayList<>(defaultKeys);
      Collections.sort(dfkeys);

      for (PropertyKey propertyKey : dfkeys) {
        String pKey = propertyKey.toString();
        String defaultDescription;
        if (propertyKey.getDefaultSupplier().get() == null) {
          defaultDescription = "";
        } else {
          defaultDescription = propertyKey.getDefaultSupplier().getDescription();
        }
        // Quote the whole description to escape characters such as commas.
        defaultDescription = String.format("\"%s\"", defaultDescription);

        // Write property key and default value to CSV
        String keyValueStr = pKey + "," + defaultDescription + "\n";
        if (pKey.startsWith("alluxio.user.")) {
          fileWriter = fileWriterMap.get("user");
        } else if (pKey.startsWith("alluxio.master.")) {
          fileWriter = fileWriterMap.get("master");
        } else if (pKey.startsWith("alluxio.worker.")) {
          fileWriter = fileWriterMap.get("worker");
        } else if (pKey.startsWith("alluxio.security.")) {
          fileWriter = fileWriterMap.get("security");
        } else if (pKey.startsWith("alluxio.keyvalue.")) {
          fileWriter = fileWriterMap.get("key-value");
        } else if (pKey.startsWith("alluxio.integration")) {
          fileWriter = fileWriterMap.get("cluster-management");
        } else {
          fileWriter = fileWriterMap.get("common");
        }
        fileWriter.append(keyValueStr);
      }

      LOG.info("Property Key CSV files were created successfully.");
    } catch (Exception e) {
      throw closer.rethrow(e);
    } finally {
      try {
        closer.close();
      } catch (IOException e) {
        LOG.error("Error while flushing/closing Property Key CSV FileWriter", e);
      }
    }
  }
893279
public void writeToExcel(List<? extends Object> datas, boolean hasTitle,
                             OutputStream outputStream, boolean transverse) throws IOException {
        writeToExcel(datas, hasTitle, outputStream, IN_MEMORY, transverse);
    }
390518
public static void writeCSV(DataObjectModel model, Collection<? extends DataObject> collection, OutputStream os) throws IOException
    {
        BufferedOutputStream bos = new BufferedOutputStream(os);
        OutputStreamWriter osw = new OutputStreamWriter(bos, "ISO-8859-1");
        CSVWriter writer = new CSVWriter(osw, ',', '"', "\r\n");
        String[] line = model.getProperties();
        writer.writeNext(line);
        for (DataObject dob : collection)
        {
            int index = 0;
            for (String property : model.getPropertyList())
            {
                Object value = dob.get(property);
                if (value != null)
                {
                    line[index++] = value.toString();
                }
                else
                {
                    line[index++] = "";
                }
            }
            writer.writeNext(line);
        }
        writer.flush();
    }
205562
public void writeToExcel(List<? extends Object> datas, boolean hasTitle, String path,
                             int inMemory, boolean transverse) throws IOException {
        writeToExcel(datas, hasTitle, new FileOutputStream(path), inMemory, transverse);
    }
697242
public void write(BufferedWriter writer) throws Exception {
		Enumeration enm;

		// header
		writer.write("# generated " + new Date());
		writer.newLine();

		enm = elements();

		while (enm.hasMoreElements()) {
			writer.write(enm.nextElement().toString());
			writer.newLine();
		}

		writer.flush();
		writer.close();
	}
372739
public void writeByteCurrentPosition(byte v) throws IOException {
    int index = (int)(position - bufferOffset);
    if (index < maxBufferSize) {
      buffer[index] = v;
      isByte[index] = true;
      if (index + 1 > currentBufferSize) currentBufferSize = index + 1;
      if (index + 1 >= maxBufferSize) {
        writeBuffer();
        newBuffer(position + 1);
      }
    } else {
      aFile.write(v);
    }
    position++;
  }
892675
protected void writeCsv(final MBasicTable table, final OutputStream outputStream,
			final DateFormat dateFormat) throws IOException {
		// récupération des informations utiles
		final int columnCount = table.getColumnModel().getColumnCount();
		final int rowCount = table.getRowCount();
		final String charset = System.getProperty("file.encoding");
		final Writer out = new OutputStreamWriter(outputStream, charset);

		final char csvSeparator = CSV_SEPARATOR;
		// le séparateur des .csv (',' à l'américaine)
		final NumberFormat decimalFormat = NumberFormat.getInstance(Locale.US);
		decimalFormat.setGroupingUsed(false);
		final String eol = System.getProperty("line.separator");

		// titres des colonnes
		writeCsvHeader(table, out, csvSeparator);

		// les données proprement dites (ligne par ligne puis colonne par colonne)
		Object value;
		String text;
		for (int k = 0; k < rowCount; k++) {
			for (int i = 0; i < columnCount; i++) {
				value = getValueAt(table, k, i);

				if (value instanceof Number) {
					text = decimalFormat.format(value);
				} else if (value instanceof Date) {
					text = dateFormat.format(value);
				} else if (value instanceof Boolean) {
					text = value.toString();
				} else {
					text = getTextAt(table, k, i);
					text = formatCsv(text, csvSeparator);
				}

				out.write(text);
				if (i < columnCount - 1) {
					out.write(csvSeparator);
				}
			}
			if (k < rowCount - 1) {
				out.write(eol);
			}
		}
		out.flush();
	}
1048710
public void write(int v) throws IOException {
	byte b[] = new byte[1];
	b[0] = (byte) v;
	pos += blob.write(b, 0, pos, 1);
    }