writeline()

Functions like a file.writeline() call; however, it stores into the object's
cached memory rather than a file's IO.
19248
def writeline(self, addition):
        
        addition = addition.strip()
        self.held = self.held + addition + "\n"
14161
public <T> File writeLines(Collection<T> list) throws IORuntimeException {
		return writeLines(list, false);
	}
837571
public void writeLine() throws IORuntimeException {
		try {
			writer.write(config.lineDelimiter);
		} catch (IOException e) {
			throw new IORuntimeException(e);
		}
		newline = true;
	}
789640
def _other_wrapper(self, name, writing):
        
        io_attr = getattr(self._io, name)

        def other_wrapper(*args, **kwargs):
            """Wrap all other calls to the stream Object.

            We do this to track changes to the write pointer.  Anything that
            moves the write pointer in a file open for appending should move
            the read pointer as well.

            Args:
                *args: Pass through args.
                **kwargs: Pass through kwargs.

            Returns:
                Wrapped stream object method.
            """
            write_seek = self._io.tell()
            ret_value = io_attr(*args, **kwargs)
            if write_seek != self._io.tell():
                self._read_seek = self._io.tell()
                self._read_whence = 0
            if not writing or not IS_PY2:
                return ret_value

        return other_wrapper
978174
@Override
	public void writeObject(Object o)
	{
		synchronized (this)
		{
			ArrayList<Object> prePending = objPrePendingCache.get(o);
			if (prePending == null)
			{
				boolean oldWritingObject = writingObject;
				writingObject = true;
				try
				{
					super.writeObject(o);
				}
				finally
				{
					writingObject = oldWritingObject;
				}
			}
			else
			{
				flushPrePending.clear();
				flushPrePending.addAll(prePending);
			}

			// root object
			if (!writingObject)
			{
				boolean isNotCached = prePending == null;
				// is not cached, add to cache
				if (isNotCached && o != null)
				{
					prePending = new ArrayList<Object>();
					prePending.addAll(flushPrePending);
					objPrePendingCache.put(o, prePending);
				}

				// add to pending
				flushPending.addAll(flushPrePending);
				flushPendingStat.addAll(flushPrePending);
				flushPrePending.clear();

				if (isNotCached && flushPending.contains(o))
				{
					flushPendingStat.remove(o);
				}
				else
				{
					flushPending.add(o);
				}
				if (needOwner)
				{
					this.flushPending.remove(owner);
					this.flushPending.add(0, owner);
				}
			}
		}
	}
1055488
protected void drain() throws IOException {
        if (primitiveTypes == null || primitiveTypesBuffer == null) {
            return;
        }

        // If we got here we have a Stream previously created
        int offset = 0;
        byte[] written = primitiveTypesBuffer.toByteArray();
        // Normalize the primitive data
        while (offset < written.length) {
            int toWrite = written.length - offset > 1024 ? 1024
                    : written.length - offset;
            if (toWrite < 256) {
                output.writeByte(TC_BLOCKDATA);
                output.writeByte((byte) toWrite);
            } else {
                output.writeByte(TC_BLOCKDATALONG);
                output.writeInt(toWrite);
            }

            // write primitive types we had and the marker of end-of-buffer
            output.write(written, offset, toWrite);
            offset += toWrite;
        }

        // and now we're clean to a state where we can write an object
        primitiveTypes = null;
        primitiveTypesBuffer = null;
    }
612631
def _file_lines(self, filename):
        """"""
        try:
            return self._file_lines_cache[filename]
        except KeyError:
            if os.path.isfile(filename):
                with open(filename) as python_file:
                    self._file_lines_cache[filename] = python_file.readlines()
            else:
                self._file_lines_cache[filename] = ""

            return self._file_lines_cache[filename]
1161313
public void save() throws IOException {
	if (!file.exists()) file.createFile(true);
	OutputStream out = IOUtil.toBufferedOutputStream(file.getOutputStream());
	Iterator it = sections.keySet().iterator();
	PrintWriter output = new PrintWriter(out);
	try {
	    while (it.hasNext()) {
		String strSection = (String) it.next();
		output.println("[" + strSection + "]");
		Map section = getSectionEL(strSection);
		Iterator iit = section.keySet().iterator();
		while (iit.hasNext()) {
		    String key = (String) iit.next();
		    output.println(key + "=" + section.get(key));
		}
	    }
	}
	finally {
	    IOUtil.flushEL(output);
	    IOUtil.closeEL(output);
	    IOUtil.flushEL(out);
	    IOUtil.closeEL(out);
	}
    }
1157442
static int write(FileDescriptor fd, ByteBuffer src, long position,
                     NativeDispatcher nd)
        throws IOException
    {
        if (src instanceof DirectBuffer)
            return writeFromNativeBuffer(fd, src, position, nd);

        // Substitute a native buffer
        int pos = src.position();
        int lim = src.limit();
        assert (pos <= lim);
        int rem = (pos <= lim ? lim - pos : 0);
        ByteBuffer bb = Util.getTemporaryDirectBuffer(rem);
        try {
            bb.put(src);
            bb.flip();
            // Do not update src until we see how many bytes were written
            src.position(pos);

            int n = writeFromNativeBuffer(fd, bb, position, nd);
            if (n > 0) {
                // now update src
                src.position(pos + n);
            }
            return n;
        } finally {
            Util.offerFirstTemporaryDirectBuffer(bb);
        }
    }
554472
void write(File f) throws FileNotFoundException, IOException {
		try (ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(f))) {
			os.writeObject(this);
		}
	}
695967
public void write(byte[] buf, int off, int len) throws IOException {
    while (true) {
      lockW.lock();
      try {
        // fail if closed
        checkClosed();
        
        final int lenToWrite = Math.min(len, length - availableCount.get());
        final int lenForward = Math.min(lenToWrite, length - writeCursor);
        final int lenRemaining = lenToWrite - lenForward;
        
        // after writeCursor
        if (lenForward > 0) {
          System.arraycopy(buf, off, bytes, writeCursor, lenForward);
          incWriteCursor(lenForward);
        }
        
        // before writeCursor
        if (lenRemaining > 0) {
          System.arraycopy(buf, off + lenForward, bytes, 0, lenRemaining);
          incWriteCursor(lenRemaining);
        } 
        
        availableCount.addAndGet(lenToWrite);
        totalWritten += lenToWrite;
        
        // modify offset and len for next iteration
        off += lenToWrite;
        len -= lenToWrite;        
        if (len == 0) {
          return;
        }
      } finally {
        lockW.unlock();
      }
      sleep(1);
    }
  }
490266
function _writeFile(i_sFilename, i_oFile, i_oCallback) {
    var l_sFilename = i_sFilename,
        l_oBuffer = new Buffer(i_oFile.fileData); // filedata is Uint8Array
    fs.writeFile(l_sFilename, l_oBuffer, function(err) {
        if (err) {
            console.log("Error writting file ", err);
            l_sFilename = null;
        }
        i_oCallback(l_sFilename);
    });
}
377085
public static void serialize(File file, SerializableObject object) throws IOException {
		AtomicFile atomicFile = new AtomicFile(file);
		FileOutputStream stream = null;
		try {
			stream = atomicFile.startWrite();
			DataOutputStream out = new DataOutputStream(stream);
			object.writeExternal(out);
			atomicFile.finishWrite(stream); // serialization was successful
		} catch (Exception e) {
			atomicFile.failWrite(stream); // serialization failed
			throw new IOException(e); // throw exception up the chain
		}
	}
845389
public void write(ObjectWriter out, PersistedValueData vd) throws IOException
   {
      out.writeInt(SerializationConstants.PERSISTED_VALUE_DATA);
      out.writeInt(vd.getOrderNumber());

      boolean isByteArray = vd.isByteArray();
      out.writeBoolean(isByteArray);

      if (isByteArray)
      {
         byte[] data = vd.getAsByteArray();
         out.writeInt(data.length);
         out.write(data);
      }
      else
      {
         // write file content
         FilePersistedValueData streamed = (FilePersistedValueData)vd;

         InputStream in = null;

         if (streamed.getFile() == null && vd instanceof StreamPersistedValueData)
         {
            if (((StreamPersistedValueData)vd).getTempFile() != null)
            {
               in = PrivilegedFileHelper.fileInputStream(((StreamPersistedValueData)vd).getTempFile());
            }
         }
         else
         {
            in = streamed.getAsStream();
         }

         if (streamed.getFile() instanceof SerializationSpoolFile)
         {
            SerializationSpoolFile ssf = (SerializationSpoolFile)streamed.getFile();
            out.writeString(ssf.getId());
            out.writeLong(0);
         }
         else
         {
            // write property id - used for reread data optimization
            String id = IdGenerator.generate();
            out.writeString(id);

            if (in == null)
            {
               // Deleted state usecase
               out.writeLong(SerializationConstants.NULL_FILE);
            }
            else
            {
               out.writeLong(vd.getLength());
               try
               {
                  byte[] buf = new byte[SerializationConstants.INTERNAL_BUFFER_SIZE];
                  int l = 0;
                  while ((l = in.read(buf)) >= 0)
                  {
                     out.write(buf, 0, l);
                  }
               }
               finally
               {
                  in.close();
               }
            }
         }
      }
   }
129861
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
        // read values
        in.defaultReadObject();

        OutputStream output = getOutputStream();
        if (cachedContent != null) {
            output.write(cachedContent);
        }
        output.close();

        cachedContent = null;
    }
593978
private void writeObject(ObjectOutputStream out) throws IOException {
        out.writeObject(clazz);
        out.writeInt(defaultBatchSize);
        out.writeInt(queryIndex);
        out.writeObject(cursor);
        out.writeObject(generators);
        out.writeInt(generatorIndex);
        writeObjects(out);
    }
593840
function write (chunk, encoding, fn) {
  if (!this._parserInit) init(this);
  debug('write(%o bytes)', chunk.length);

  // XXX: old Writable stream API compat... remove at some point...
  if ('function' == typeof encoding) fn = encoding;

  data(this, chunk, null, fn);
}