AdvancedFileStream.cs :  » PDF » SharpPDF » sharpPDF » Fonts » TTF » IO » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » PDF » SharpPDF 
SharpPDF » sharpPDF » Fonts » TTF » IO » AdvancedFileStream.cs
using System;
using System.IO;
using System.Text;

using sharpPDF;
using sharpPDF.Exceptions;

namespace sharpPDF.Fonts.TTF.IO{
  /// <summary>
  /// Class thet represents an extension of FileStream that reads/stores TTF File Format
  /// (Big-Endian and TTF variables, Based on Microsoft TTF Specifications)
  /// </summary>
  internal class AdvancedFileStream : FileStream
  {

    /// <summary>
    /// Class's Constructor
    /// </summary>
    /// <param name="fileName">Name of the file</param>
    /// <param name="fileMode">File Mode</param>
    public AdvancedFileStream(string fileName,FileMode fileMode):base(fileName, fileMode)
    {
      
    }

    /// <summary>
    /// Method that reads a string from the stream
    /// </summary>
    /// <param name="length">Lenght of the string</param>
    /// <returns>String</returns>
    public string readString(int length)
    {    
      try 
      {
        byte[] buffer = new byte[length];
        StringBuilder resultString = new StringBuilder();
        base.Read(buffer,0,buffer.Length);      
        for(int i = 0; i < length; i++)
        {
          resultString.Append(Convert.ToChar(buffer[i]));
        }
        return resultString.ToString();
      } 
      catch (IOException ex) 
      {
        throw new pdfGenericIOException(ex.Message,ex);
      }      
    }

    /// <summary>
    /// Method that reads an unicode string from the stream
    /// </summary>
    /// <param name="length">Length of the string</param>
    /// <returns>String</returns>
    public string readUnicodeString(int length)
    {
      byte[] buffer = new byte[length];
      StringBuilder resultString = new StringBuilder();
      base.Read(buffer,0,buffer.Length);      
      for(int i = 0; i < length; i+=2)
      {
        resultString.Append(Convert.ToChar((buffer[i] << 8) + buffer[i+1]));
      }
      return resultString.ToString();
    }

    /// <summary>
    /// Method that reads an Unsigned Long Big-Endian from the stream
    /// </summary>
    /// <returns>Unsigned Long</returns>
    public int readULong_BE()
    {
      byte[] buffer = new byte[4];
      int returnValue = 0;
      base.Read(buffer,0,buffer.Length);      
      returnValue = (buffer[0] << 24) + (buffer[1] << 16) + (buffer[2] << 8) + buffer[3];
      buffer = null;
      return returnValue;
    }

    /// <summary>
    /// Method that reads a Short Big-Endian
    /// </summary>
    /// <returns>Short</returns>
    public short readShort_BE()
    {
      byte[] buffer = new byte[2];
      short returnValue = 0;
      base.Read(buffer,0,buffer.Length);      
      returnValue = (short)((buffer[0] << 8) + buffer[1]);
      buffer = null;
      return returnValue;
    }

    /// <summary>
    /// Method that reads a Unsigned Short Big-Endian
    /// </summary>
    /// <returns>Unsigned Short</returns>
    public int readUShort_BE()
    {
      byte[] buffer = new byte[2];
      int returnValue = 0;
      base.Read(buffer,0,buffer.Length);      
      returnValue = (buffer[0] << 8) + buffer[1];
      buffer = null;
      return returnValue;
    }

    /// <summary>
    /// Method that reads an Integer
    /// </summary>
    /// <returns>Integer</returns>
    public int readInt()
    {
      byte[] buffer = new byte[2];
      int returnValue = 0;
      base.Read(buffer,0,buffer.Length);      
      returnValue = (buffer[1]) + buffer[0];
      buffer = null;
      return returnValue;
    }

    /// <summary>
    /// Method that reads an Integer Big-Endian
    /// </summary>
    /// <returns>Integer</returns>
    public int readInt_BE()
    {
      byte[] buffer = new byte[2];
      int returnValue = 0;
      base.Read(buffer,0,buffer.Length);      
      returnValue = (buffer[0] << 8) + buffer[1];
      buffer = null;
      return returnValue;
    }

    /// <summary>
    /// Method that read a Byte
    /// </summary>
    /// <returns>Byte</returns>
    public byte readByte()
    {
      byte[] buffer = new byte[1];
      byte returnValue = 0;
      base.Read(buffer,0,buffer.Length);      
      returnValue = buffer[0];
      buffer = null;
      return returnValue;
    }

    /// <summary>
    /// Method that read an array of Bytes
    /// </summary>
    /// <param name="length">Lenght of the array</param>
    /// <returns>Byte Array</returns>
    public byte[] readByteArray(int length)
    {
      byte[] buffer = new byte[length];
      base.Read(buffer,0,buffer.Length);
      return buffer;
    }

    /// <summary>
    /// Method that read an array of Bytes Big-Endian
    /// </summary>
    /// <param name="length">Lenght of the array</param>
    /// <returns>Byte Array</returns>
    public byte[] readByteArray_BE(int length)
    {
      byte[] buffer = new byte[length];
      base.Read(buffer,0,buffer.Length);
      return Encoding.Convert(Encoding.BigEndianUnicode, Encoding.Unicode, buffer,0,buffer.Length);
    }

    /// <summary>
    /// Method that sets the position of the stream
    /// </summary>
    /// <param name="offset"></param>
    public void SetPosition(long offset)
    {
      base.Position = offset;
    }

    /// <summary>
    /// Method that skip a number of Bytes
    /// </summary>
    /// <param name="length">Bytes to skip</param>
    public void SkipBytes(long length)
    {
      base.Position += length;
    }    

  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.