Write the given bytes to the given virtual file, replacing its current contents (if any) or creating a new file if
one does not exist.

@param virtualFile the virtual file to write
@param bytes       the bytes
@throws IOException if an error occurs
358078
public static void writeFile(VirtualFile virtualFile, byte[] bytes) throws IOException {
        final File file = virtualFile.getPhysicalFile();
        file.getParentFile().mkdirs();
        final FileOutputStream fos = new FileOutputStream(file);
        try {
            fos.write(bytes);
            fos.close();
        } finally {
            safeClose(fos);
        }
    }
395464
void writeBytes(byte[] bytes) throws IOException {
        int size = bytes.length;
        if (size < 256) {
            output.writeByte(BIN_8);
            output.writeByte(size);
        } else if (size < 65536) {
            output.writeByte(BIN_16);
            output.writeShort(size);
        } else {
            output.writeByte(BIN_32);
            output.writeInt(size);
        }
        output.write(bytes);
    }
252789
public void writeNestedLibrary(String destination, Library library)
			throws IOException {
		File file = library.getFile();
		JarArchiveEntry entry = new JarArchiveEntry(destination + library.getName());
		entry.setTime(getNestedLibraryTime(file));
		new CrcAndSize(file).setupStoredEntry(entry);
		writeEntry(entry, new InputStreamEntryWriter(new FileInputStream(file), true),
				new LibraryUnpackHandler(library));
	}
276347
def _write(self, session, openFile, replaceParamFile):
        
        # Write lines
        openFile.write('GSSHA_CHAN\n')

        alpha = vwp(self.alpha, replaceParamFile)
        try:
            openFile.write('ALPHA%s%.6f\n' % (' ' * 7, alpha))
        except:
            openFile.write('ALPHA%s%s\n' % (' ' * 7, alpha))

        beta = vwp(self.beta, replaceParamFile)
        try:
            openFile.write('BETA%s%.6f\n' % (' ' * 8, beta))
        except:
            openFile.write('BETA%s%s\n' % (' ' * 8, beta))

        theta = vwp(self.theta, replaceParamFile)
        try:
            openFile.write('THETA%s%.6f\n' % (' ' * 7, theta))
        except:
            openFile.write('THETA%s%s\n' % (' ' * 7, theta))

        openFile.write('LINKS%s%s\n' % (' ' * 7, self.links))
        openFile.write('MAXNODES%s%s\n' % (' ' * 4, self.maxNodes))

        # Retrieve StreamLinks
        links = self.getOrderedLinks(session)

        self._writeConnectivity(links=links,
                                fileObject=openFile)
        self._writeLinks(links=links,
                         fileObject=openFile,
                         replaceParamFile=replaceParamFile)
1046198
@Override
    public ZeroCopyFileWriter write(String event) {
//        String realPath = FileHandlerUtil.generateOutputFilePath(path);

        String realPath = FileHandlerUtil.generateOutputFilePath(
    			path, 
    			FileHandlerUtil.generateAuditFileName());

        try {
           /** Close last instance for random access file. **/
			if (randomAccessFile != null && !realPath.equals(lastRealPath)) {
				this.stop();
			}
			
			if (randomAccessFile == null) {
				lastRealPath = realPath;
				randomAccessFile = new RandomAccessFile(new File(realPath), CoreConstants.READ_WRITE);
			}
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        fileChannel = randomAccessFile.getChannel();
        
        String str2 = event + CoreConstants.NEW_LINE;

        long numBytes = str2.getBytes().length;

        InputStream inputStream = new ByteArrayInputStream(str2.getBytes(Charset.forName("UTF-8")));

        try {

            // move the cursor to the end of the file
            randomAccessFile.seek(randomAccessFile.length());

            // obtain the a file channel from the RandomAccessFile
            try (ReadableByteChannel inputChannel = Channels.newChannel(inputStream);) {
                fileChannel.transferFrom(inputChannel, randomAccessFile.length(), numBytes);
            } catch (IOException e) {
                e.printStackTrace();
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
        return this;
    }
416321
public final void write(byte[] data) {
    if (sendBinary) {
      int prev = 0;
      for (int i = 0;i < data.length;i++) {
        if (data[i] == -1) {
          rawWrite(data, prev, i - prev);
          send(new byte[]{-1, -1});
          prev = i + 1;
        }
      }
      rawWrite(data, prev, data.length - prev);
    } else {
      for (int i = 0;i < data.length;i++) {
        data[i] = (byte)(data[i] & 0x7F);
      }
      send(data);
    }
  }
872788
public static void writeToFile(final File fileNode, final byte[] data) throws FrameworkException, IOException {

		setFileProperties(fileNode);

		FileUtils.writeByteArrayToFile(fileNode.getFileOnDisk(), data);

	}
676682
@Override
    public void write(byte[] b) throws IOException {
        if (b.length == 0)
            return;
        fos().write(b);
        currFileBytesWritten += b.length;
        totalBytesWritten += b.length;
    }
1374524
public BinaryEncoder writeBytes(byte[] bytes) throws IOException {
    writeLong(bytes.length);
    output.write(bytes, 0, bytes.length);
    return this;
  }
971311
public void writeBytes(byte[] buffer, int offset, int length)
        throws IOException
    {
        if (buffer == null) {
            os.write('N');
        }
        else {
            os.write('B');
            os.write(length << 8);
            os.write(length);
            os.write(buffer, offset, length);
        }
    }
914617
public void write(byte myByte) throws IOException {
        onNewLine = false;
        buffer.put(myByte);
        if (!buffer.hasRemaining()) {
            flush();
        }
    }
1344001
private void writePendingToFile() throws java.io.IOException, InternalLogException, LogIncompatibleException
    {
        if (tc.isEntryEnabled())
            Tr.entry(tc, "writePendingToFile");

        synchronized (_pendingWriteList)
        {
            LogRecord[] records = (LogRecord[]) _pendingWriteList.toArray(new LogRecord[0]);

            // Don't use vectored IO unless we're told to.
            if (!Boolean.getBoolean("com.ibm.ws.recoverylog.spi.UseVectoredIO"))
            {
                // Put the file header at the front of the list
                ByteBuffer header = (ByteBuffer) _fileBuffer.duplicate().position(0).limit(_logFileHeader.length());
                _fileChannel.write(header, 0);

                // Write the remainder of the list
                for (int i = 0; i < records.length; i++)
                {
                    if (tc.isDebugEnabled())
                        Tr.debug(tc, "Performing write at position " + records[i].absolutePosition());
                    _fileChannel.write((ByteBuffer) records[i]._buffer.flip(), records[i].absolutePosition());
                }
            }
            else
            {
                // Sort the records into ascending order based on their absolute
                // position in the file.  We're going to try and keep the disk
                // moving forward.
                Arrays.sort(records, _recordComparator);

                // Now separate the records into two arrays:
                //   o ByteBuffers of data
                //   o Absolute File positions
                ByteBuffer[] buffers = new ByteBuffer[records.length + 1];
                int[] positions = new int[records.length + 1];

                for (int i = 0; i < records.length; i++)
                {
                    buffers[i + 1] = (ByteBuffer) records[i]._buffer.flip();
                    positions[i + 1] = records[i].absolutePosition();
                }

                // Put the file header at the front of the list
                buffers[0] = (ByteBuffer) _fileBuffer.duplicate().position(0).limit(_logFileHeader.length());
                positions[0] = 0;

                // Here's where we go through the list and attempt to write
                // batches of adjacent records using vectored I/O.
                int idx = 0;
                while (idx < buffers.length)
                {
                    int min = idx;
                    int max = idx;

                    // Somewhere in the middle
                    while (max <= (buffers.length - 2))
                    {
                        if (positions[max + 1] == (positions[max] + buffers[max].remaining()))
                            max++;
                    }

                    // Do the actual writes                    
                    _fileChannel.position(positions[min]);
                    _fileChannel.write(buffers, min, (max - min + 1));

                    // Go back and find the next batch
                    idx = max + 1;
                }
            }

            // Cleanup the pending write list for the next force
            _pendingWriteList.clear();
        }

        if (tc.isEntryEnabled())
            Tr.exit(tc, "writePendingToFile");
    }
195791
@Override
    public void write(byte[] b, int off, int len) throws IOException {
        if (b.length == 0)
            return;
        fos().write(b, off, len);
        currFileBytesWritten += len;
        totalBytesWritten += len;
    }
997488
public static boolean writeBytesToFile(byte[] bytes, File f) {
        try {
            FileOutputStream fout = new FileOutputStream(f);
            fout.write(bytes);
            fout.close();
        } catch (Exception e) {
            System.out.println("Error writing byte[] to file: "
                    + e.getMessage());
            return false;
        }
        return true;
    }
125753
static void writeBytesToFile(File file, byte[] bytes) throws IOException {
        BufferedOutputStream bos = null;

        try {
            FileOutputStream fos = new FileOutputStream(file);
            bos = new BufferedOutputStream(fos);
            bos.write(bytes);
        } finally {
            if (bos != null) {
                try  {
                    // flush and close the BufferedOutputStream
                    bos.flush();
                    bos.close();
                } catch (Exception e) {}
            }
        }
    }
435313
public static void copyFile(InputStream _inputStream, String newFile) throws IOException {
        try (InputStream inputStream = _inputStream;
             FileOutputStream outputStream = new FileOutputStream(newFile)) {
            int length = 2097152;
            byte[] buffer = new byte[length];
            while (true) {
                int read = inputStream.read(buffer);
                if (read == -1) {
                    outputStream.flush();
                    break;
                } else {
                    outputStream.write(buffer, 0, read);
                }
            }
        }
    }
1021936
public static void writeByteArrayToFile(final String filename, final byte[] byteArray)
		throws IOException
	{
		final File file = new File(filename);
		writeByteArrayToFile(file, byteArray);
	}