working on it ...

Filters

Explore Public Snippets

Sort by

Found 13k snippets matching: write

    public by sTiLL-iLL modified Dec 27, 2014  307436  0  5  14

    my nonblocking, threadsafe file writer/appender for nodejs. works great with clustered servers, and child processes that write to shared or static file-stores

    my nonblocking, threadsafe file writer/appender for nodejs. works great with clustered servers, and child processes that write to shared or static file-stores: scribbles.js
    // scribbles.js a nonblocking, threadsafe file writer/appender for nodejs
    
    var fs = require('fs'),
    	pth = require('path'),
    	cueMngr = {};
    
    function Scribbles(fileNm) {
    	this.handle = fileNm;
    	this.canWrite = false;
    	this.actionsRoster = [];
    };
    
    var scribbles = Scribbles.prototype;
    
    scribbles.action = function (err, dta, actionCue) {
    	if (err) {
    		throw err;
    	}
    	return actionCue();
    }
    
    scribbles.assign = function (func) {
    	this.action = func;
    	return this;
    }
    
    scribbles.scribble = function (dta, func) {
    	if (this.canWrite) {
    		this.actionCue = dta;
    		if (func) {
    			this.actionsRoster.push(func);
    		}
    	} 
    	else {
    		this.canWrite = true;
    		var slf = this,
    			taskProxy = {};
    		fs.appendFile(this.handle, dta, function (err) {
    			function actionCue() {
    				slf.canWrite = false;
    				if (slf.actionCue) {
    					var dta = slf.actionCue;
    					slf.scribble(dta);
    					slf.actionCue = null;
    				}
    			}
    			slf.action(err, dta, actionCue);
    			while (taskProxy = slf.actionsRoster.shift()) {
    				return taskProxy(err);
    			}
    			if (func) {
    				return func(err);
    			}
    		});
    	}
    	return this;
    };
    
    module.exports = function (fil) {
    	var nm = pth.resolve(fil);
    	return (cueMngr[nm] = cueMngr[nm] || new Scribbles(fil));
    }
    
    

    public by sukhjinderkahlon modified Mar 9, 2016  325907  6  5  0

    How to Work with Excel Files Using Apache POI

    This code will work as a utility to read and write excel files using Apache POI Library. 3.13
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    
    import org.apache.poi.hssf.usermodel.HSSFCell;
    import org.apache.poi.hssf.usermodel.HSSFRow;
    import org.apache.poi.hssf.usermodel.HSSFSheet;
    import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    import org.apache.poi.xssf.usermodel.XSSFCell;
    import org.apache.poi.xssf.usermodel.XSSFRow;
    import org.apache.poi.xssf.usermodel.XSSFSheet;
    import org.apache.poi.xssf.usermodel.XSSFWorkbook;
    
    public class ExcelUtils {
    
    	private static HSSFSheet ExcelWSheet;
    	private static HSSFWorkbook ExcelWBook;
    	private static HSSFCell Cell;
    
    	private static HSSFRow Row;
    	
    	private static String filePath;
    	public static void setExcelFile(String Path,String SheetName) throws Exception {
    
    			try {
    
       			// Open the Excel file
    				filePath=Path;
    
    			FileInputStream ExcelFile = new FileInputStream(Path);
    
    			// Access the required test data sheet
    
    			ExcelWBook = new HSSFWorkbook(ExcelFile);
    
    			ExcelWSheet = ExcelWBook.getSheet(SheetName);
    			
    
    			} catch (Exception e){
    
    				throw (e);
    
    			}
    
    	}
    
    	//This method is to read the test data from the Excel cell, in this we are passing parameters as Row num and Col num
    
        public static String getCellData(int RowNum, int ColNum) throws Exception{
    
    			try{
    
      			Cell = ExcelWSheet.getRow(RowNum).getCell(ColNum);
    
      			String CellData = Cell.getStringCellValue();
    
      			return CellData;
    
      			}catch (Exception e){
    
    				return"";
    
      			}
    
        }
    
    
        
      //This method is to write in the Excel cell, Row num and Col num are the parameters
    
    	public static void setCellData(String Result,  int RowNum, int ColNum) throws Exception	{
    
    			try{
    
      			Row  = ExcelWSheet.getRow(RowNum);
    
    			Cell = Row.getCell(ColNum, Row.RETURN_BLANK_AS_NULL);
    
    			if (Cell == null) {
    
    				Cell = Row.createCell(ColNum);
    
    				Cell.setCellValue(Result);
    
    				} else {
    
    					Cell.setCellValue(Result);
    
    				}
    
      // Constant variables Test Data path and Test Data file name
    
      				FileOutputStream fileOut = new FileOutputStream(filePath);
    
      				ExcelWBook.write(fileOut);
    
      				fileOut.flush();
    
    					fileOut.close();
    
    				}catch(Exception e){
    
    					throw (e);
    
    			}
    
    		}
    
    	
    }
              

    public by Geometry modified Jul 31, 2016  148137  0  3  0

    GetCommandBuffer: Gets the bytes representing the specified command. returned buffer can be used to streamline multiple writes into one Write on the Socket using the <see cref="M:Enyim.Caching.Memcached.PooledSocket.Write(IList&lt;ArraySegment&lt;b...

    Gets the bytes representing the specified command. returned buffer can be used to streamline multiple writes into one Write on the Socket using the The command to be converted. The buffer containing the bytes representing the command. The command must be terminated by \r\n. The Nagle algorithm is disabled on the socket to speed things up, so it's
    C#
    using System;
    using System.IO;
    using System.Text;
    using System.Collections.Generic;
    
    /// <summary>
    /// Gets the bytes representing the specified command. returned buffer can be used to streamline multiple writes into one Write on the Socket
    /// using the <see cref="M:Enyim.Caching.Memcached.PooledSocket.Write(IList&lt;ArraySegment&lt;byte&gt;&gt;)"/>
    /// </summary>
    /// <param name="value">The command to be converted.</param>
    /// <returns>The buffer containing the bytes representing the command. The command must be terminated by \r\n.</returns>
    /// <remarks>The Nagle algorithm is disabled on the socket to speed things up, so it's recommended to convert a command into a buffer
    /// and use the <see cref="M:Enyim.Caching.Memcached.PooledSocket.Write(IList&lt;ArraySegment&lt;byte&gt;&gt;)"/> to send the command and the additional buffers in one transaction.</remarks>
    public unsafe static IList<ArraySegment<byte>> GetCommandBuffer(string value)
    {
    	var data = new ArraySegment<byte>(Encoding.ASCII.GetBytes(value));
    
    	return new ArraySegment<byte>[] { data };
    }

    public by Geometry modified Jul 31, 2016  1167  0  4  0

    GetCommandBuffer: Gets the bytes representing the specified command. returned buffer can be used to streamline multiple writes into one Write on the Socket using the <see cref="M:Enyim.Caching.Memcached.PooledSocket.Write(IList&lt;ArraySegment&lt;b...

    Gets the bytes representing the specified command. returned buffer can be used to streamline multiple writes into one Write on the Socket using the The command to be converted. The buffer containing the bytes representing the command. The command must be terminated by \r\n. The Nagle algorithm is disabled on the socket to speed things up, so it's
    using System;
    using System.IO;
    using System.Text;
    using System.Collections.Generic;
    
    /// <summary>
    /// Gets the bytes representing the specified command. returned buffer can be used to streamline multiple writes into one Write on the Socket
    /// using the <see cref="M:Enyim.Caching.Memcached.PooledSocket.Write(IList&lt;ArraySegment&lt;byte&gt;&gt;)"/>
    /// </summary>
    /// <param name="value">The command to be converted.</param>
    /// <returns>The buffer containing the bytes representing the command. The command must be terminated by \r\n.</returns>
    /// <remarks>The Nagle algorithm is disabled on the socket to speed things up, so it's recommended to convert a command into a buffer
    /// and use the <see cref="M:Enyim.Caching.Memcached.PooledSocket.Write(IList&lt;ArraySegment&lt;byte&gt;&gt;)"/> to send the command and the additional buffers in one transaction.</remarks>
    public unsafe static IList<ArraySegment<byte>> GetCommandBuffer(string value)
    {
    	var data = new ArraySegment<byte>(Encoding.ASCII.GetBytes(value));
    
    	return new ArraySegment<byte>[] { data };
    }

    public by sherazam modified Feb 24, 2016  2372  0  6  0

    How to Read and Write XMP Data to Images inside .NET Apps

    // Enter here the actual content of the snippet.//Create XMP Metadata, Write It And Read From File
    
    //[C# Code Sample]
    
    // Specify the size of image by defining a Rectangle 
    Aspose.Imaging.Rectangle rect = new Aspose.Imaging.Rectangle(0, 0, 100, 200);
    
    TiffOptions tiffOptions = new TiffOptions(TiffExpectedFormat.TiffJpegRGB);
    tiffOptions.Photometric = TiffPhotometrics.MinIsBlack;
    tiffOptions.BitsPerSample = new ushort[] { 8 };
    
    // create the brand new image just for sample purposes
    using (var image = new TiffImage(new TiffFrame(tiffOptions, rect.Width, rect.Height)))
    {
          // create an instance of XMP-Header
          Aspose.Imaging.Xmp.XmpHeaderPi xmpHeader = new Aspose.Imaging.Xmp.XmpHeaderPi(System.Guid.NewGuid().ToString());
    
          // create an instance of Xmp-TrailerPi 
          Aspose.Imaging.Xmp.XmpTrailerPi xmpTrailer = new Aspose.Imaging.Xmp.XmpTrailerPi(true);
    
          // create an instance of XMPmeta class to set different attributes
          Aspose.Imaging.Xmp.XmpMeta xmpMeta = new Aspose.Imaging.Xmp.XmpMeta();
          xmpMeta.AddAttribute("Author", "Mr Smith");
          xmpMeta.AddAttribute("Description", "The fake metadata value");
    
          // create an instance of XmpPacketWrapper that contains all metadata
          Aspose.Imaging.Xmp.XmpPacketWrapper xmpData = new Aspose.Imaging.Xmp.XmpPacketWrapper(xmpHeader, xmpTrailer, xmpMeta);
    
          // create an instacne of Photoshop package and set photoshop attributes
          Aspose.Imaging.Xmp.Schemas.Photoshop.PhotoshopPackage photoshopPackage = new Aspose.Imaging.Xmp.Schemas.Photoshop.PhotoshopPackage();
          photoshopPackage.SetCity("London");
          photoshopPackage.SetCountry("England");
          photoshopPackage.SetColorMode(Aspose.Imaging.Xmp.Schemas.Photoshop.ColorMode.Rgb);
          photoshopPackage.SetCreatedDate(DateTime.UtcNow);
    
          // add photoshop package into XMP metadata
          xmpData.AddPackage(photoshopPackage);
    
          // create an instacne of DublinCore package and set dublinCore attributes
          Aspose.Imaging.Xmp.Schemas.DublinCore.DublinCorePackage dublinCorePackage = new Aspose.Imaging.Xmp.Schemas.DublinCore.DublinCorePackage();
          dublinCorePackage.SetAuthor("Charles Bukowski");
          dublinCorePackage.SetTitle("Confessions of a Man Insane Enough to Live With the Beasts");
          dublinCorePackage.AddValue("dc:movie", "Barfly");
    
          // add dublinCore Package into XMP metadata
          xmpData.AddPackage(dublinCorePackage);
    
          using (var ms = new MemoryStream())
          {
                        // update XMP metadata into image
                        image.XmpData = xmpData;
    
                        // Save image on the disk or in memory stream
                        image.Save(ms);
    
                        ms.Seek(0, System.IO.SeekOrigin.Begin);
    
                        // Load the image from moemory stream or from disk to read/get the metadata
                        using (var img = (TiffImage)Aspose.Imaging.Image.Load(ms))
                        {
                            // getting the XMP metadata
                            Aspose.Imaging.Xmp.XmpPacketWrapper imgXmpData = img.XmpData;
                            foreach (Aspose.Imaging.Xmp.XmpPackage package in imgXmpData.Packages)
                            {
                                // use package data ...
                            }
                        }
         }
    }
     
    //[VB.NET Code Sample]
    
    ' Specify the size of image by defining a Rectangle 
    Dim rect As New Aspose.Imaging.Rectangle(0, 0, 100, 200)
    
    Dim tiffOptions As New TiffOptions(TiffExpectedFormat.TiffJpegRGB)
    tiffOptions.Photometric = TiffPhotometrics.MinIsBlack
    tiffOptions.BitsPerSample = New UShort() {8}
    
    ' create the brand new image just for sample purposes
    Using image = New TiffImage(New TiffFrame(tiffOptions, rect.Width, rect.Height))
    	' create an instance of XMP-Header
    	Dim xmpHeader As New Aspose.Imaging.Xmp.XmpHeaderPi(System.Guid.NewGuid().ToString())
    
    	' create an instance of Xmp-TrailerPi 
    	Dim xmpTrailer As New Aspose.Imaging.Xmp.XmpTrailerPi(True)
    
    	' create an instance of XMPmeta class to set different attributes
    	Dim xmpMeta As New Aspose.Imaging.Xmp.XmpMeta()
    	xmpMeta.AddAttribute("Author", "Mr Smith")
    	xmpMeta.AddAttribute("Description", "The fake metadata value")
    
    	' create an instance of XmpPacketWrapper that contains all metadata
    	Dim xmpData As New Aspose.Imaging.Xmp.XmpPacketWrapper(xmpHeader, xmpTrailer, xmpMeta)
    
    	' create an instacne of Photoshop package and set photoshop attributes
    	Dim photoshopPackage As New Aspose.Imaging.Xmp.Schemas.Photoshop.PhotoshopPackage()
    	photoshopPackage.SetCity("London")
    	photoshopPackage.SetCountry("England")
    	photoshopPackage.SetColorMode(Aspose.Imaging.Xmp.Schemas.Photoshop.ColorMode.Rgb)
    	photoshopPackage.SetCreatedDate(DateTime.UtcNow)
    
    	' add photoshop package into XMP metadata
    	xmpData.AddPackage(photoshopPackage)
    
    	' create an instacne of DublinCore package and set dublinCore attributes
    	Dim dublinCorePackage As New Aspose.Imaging.Xmp.Schemas.DublinCore.DublinCorePackage()
    	dublinCorePackage.SetAuthor("Charles Bukowski")
    	dublinCorePackage.SetTitle("Confessions of a Man Insane Enough to Live With the Beasts")
    	dublinCorePackage.AddValue("dc:movie", "Barfly")
    
    	' add dublinCore Package into XMP metadata
    	xmpData.AddPackage(dublinCorePackage)
    
    	Using ms = New MemoryStream()
    		' update XMP metadata into image
    		image.XmpData = xmpData
    
    		' Save image on the disk or in memory stream
    		image.Save(ms)
    
    		ms.Seek(0, System.IO.SeekOrigin.Begin)
    
    		' Load the image from moemory stream or from disk to read/get the metadata
    		Using img = DirectCast(Aspose.Imaging.Image.Load(ms), TiffImage)
    			' getting the XMP metadata
    			Dim imgXmpData As Aspose.Imaging.Xmp.XmpPacketWrapper = img.XmpData
    					' use package data ...
    			For Each package As Aspose.Imaging.Xmp.XmpPackage In imgXmpData.Packages
    			Next
    		End Using
    	End Using
    End Using
    
    

    public by sTiLL-iLL modified Dec 27, 2014  6678  9  4  1

    my nonblocking, threadsafe file writer/appender for nodejs. works great with clustered servers, and child processes that write to shared or static file-stores

    my nonblocking, threadsafe file writer/appender for nodejs. works great with clustered servers, and child processes that write to shared or static file-stores: scribbles.js
    // scribbles.js a nonblocking, threadsafe file writer/appender for nodejs
    
    var fs = require('fs'),
    	pth = require('path'),
    	cueMngr = {};
    
    function Scribbles(fileNm) {
    	this.handle = fileNm;
    	this.canWrite = false;
    	this.actionsRoster = [];
    };
    
    var scribbles = Scribbles.prototype;
    
    scribbles.action = function (err, dta, actionCue) {
    	if (err) {
    		throw err;
    	}
    	return actionCue();
    }
    
    scribbles.assign = function (func) {
    	this.action = func;
    	return this;
    }
    
    scribbles.scribble = function (dta, func) {
    	if (this.canWrite) {
    		this.actionCue = dta;
    		if (func) {
    			this.actionsRoster.push(func);
    		}
    	} 
    	else {
    		this.canWrite = true;
    		var slf = this,
    			taskProxy = {};
    		fs.appendFile(this.handle, dta, function (err) {
    			function actionCue() {
    				slf.canWrite = false;
    				if (slf.actionCue) {
    					var dta = slf.actionCue;
    					slf.scribble(dta);
    					slf.actionCue = null;
    				}
    			}
    			slf.action(err, dta, actionCue);
    			while (taskProxy = slf.actionsRoster.shift()) {
    				return taskProxy(err);
    			}
    			if (func) {
    				return func(err);
    			}
    		});
    	}
    	return this;
    };
    
    module.exports = function (fil) {
    	var nm = pth.resolve(fil);
    	return (cueMngr[nm] = cueMngr[nm] || new Scribbles(fil));
    }
    
    

    public by zonaro modified Nov 10, 2015  2704  1  7  0

    Easy Write Bytes to File

    This snnipet write (or overwrite) a ByteArray to file on specific path and return a FileInfo of the created file
    public static FileInfo ToFile(this byte[] ByteArray, string FilePath)
            { 
                if (File.Exists(FilePath)) { File.Delete(FilePath); }
                System.IO.FileStream fs = new System.IO.FileStream(FilePath, System.IO.FileMode.Create, System.IO.FileAccess.Write);
                fs.Write(ByteArray, 0, ByteArray.Length);
                fs.Close();
                return new FileInfo(System.IO.Path.GetFileName(FilePath)); 
            }

    public by cghersi modified Jan 10, 2017  2027  9  5  3

    How to write bytes into file in Java

    Efficient way to write strings or bytes onto a file.
      import java.nio.file.Files;
      import java.nio.file.Paths;
    
      public static void writeFile(String path, String content) throws Exception {
    		if (isNullOrEmpty(path) || isNullOrEmpty(content)) {
    			return;
    		}
    		Files.write(Paths.get(path), content.getBytes());
    	}                     

    public by cghersi modified Sep 14, 2014  2563  0  5  1

    Write a message onto the console for debug purpose

    public static void LogOnConsole(string message)
    {
      Console.WriteLine(message);
    }
    

    public by Geometry modified Aug 7, 2016  897  0  5  0

    ToText: Initializes a new instance of the <see cref="CsvWriter"/> class to write the CSV fields to a in-memory string.

    Initializes a new instance of the class to write the CSV fields to a in-memory string. A to write to.
    /// <summary>
    ///   Initializes a new instance of the <see cref="CsvWriter"/> 
    ///   class to write the CSV fields to a in-memory string.
    /// </summary>
    /// 
    /// <param name="builder">A <see cref="T:StringBuilder"/> to write to.</param>
    /// 
    public static CsvWriter ToText(StringBuilder builder)
    {
        return new CsvWriter(new StringWriter(builder));
    }
    • Public Snippets
    • Channels Snippets