webengine/osswebengine/WebCore/platform/symbian/FileStreamSymbian.cpp
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "config.h"
       
    20 #include <../bidi.h>
       
    21 #include "FileStreamSymbian.h"
       
    22 #include "PlatformString.h"
       
    23 #include "StaticObjectsContainer.h"
       
    24 
       
    25 namespace WebCore {
       
    26 
       
    27 //------------------------------------------------------------------------------
       
    28 // FileStreamOutput
       
    29 //------------------------------------------------------------------------------
       
    30 
       
    31 FileStreamOutput::FileStreamOutput(const String& path) : m_isOpened(false)
       
    32 {
       
    33     if (m_stream.Replace(StaticObjectsContainer::instance()->fsSession(), path.des(), EFileWrite | EFileStream | EFileShareAny) == KErrNone)
       
    34         m_isOpened = true;
       
    35 }
       
    36 
       
    37 FileStreamOutput::~FileStreamOutput()
       
    38 {
       
    39     m_stream.Close();
       
    40 }
       
    41 
       
    42 StreamOutput& FileStreamOutput::operator<<(char ch)
       
    43 {
       
    44     m_stream.WriteInt8L(ch);
       
    45     return *this;
       
    46 }
       
    47 
       
    48 StreamOutput& FileStreamOutput::operator<<(unsigned char ch)
       
    49 {
       
    50     m_stream.WriteUint8L(ch);
       
    51     return *this;
       
    52 }
       
    53 
       
    54 StreamOutput& FileStreamOutput::operator<<(short sh)
       
    55 {
       
    56     m_stream.WriteInt16L(sh);
       
    57     return *this;
       
    58 }
       
    59 
       
    60 StreamOutput& FileStreamOutput::operator<<(unsigned short ush)
       
    61 {
       
    62     m_stream.WriteUint16L(ush);
       
    63     return *this;
       
    64 }
       
    65 
       
    66 StreamOutput& FileStreamOutput::operator<<(int i)
       
    67 {
       
    68     m_stream.WriteInt32L(i);
       
    69     return *this;
       
    70 }
       
    71 
       
    72 StreamOutput& FileStreamOutput::operator<<(unsigned int ui)
       
    73 {
       
    74     m_stream.WriteUint32L(ui);
       
    75     return *this;
       
    76 }
       
    77 
       
    78 StreamOutput& FileStreamOutput::operator<<(const String& str)
       
    79 {
       
    80     // we only write unicode data into the string
       
    81     int len = str.length();
       
    82     const UChar* chs = str.characters();
       
    83     m_stream.WriteInt32L(len);
       
    84     m_stream.WriteL((const TUint8*)(chs), len<<1);
       
    85     return *this;
       
    86 }
       
    87 
       
    88 StreamOutput& FileStreamOutput::operator<<(const Streamable& o)
       
    89 {
       
    90     o.write(*this);
       
    91     return *this;
       
    92 }
       
    93 
       
    94 StreamOutput& FileStreamOutput::operator<<(const StreamEndOfLine&)
       
    95 {
       
    96     return *this;
       
    97 }
       
    98 
       
    99 //------------------------------------------------------------------------------
       
   100 // FileStreamInput
       
   101 //------------------------------------------------------------------------------
       
   102 
       
   103 FileStreamInput::FileStreamInput(const String& path) : m_isOpened(false)
       
   104 {
       
   105     if (m_stream.Open(StaticObjectsContainer::instance()->fsSession(), path.des(), EFileShareReadersOnly | EFileRead | EFileStream) == KErrNone)
       
   106         m_isOpened = true;
       
   107 }
       
   108 
       
   109 FileStreamInput::~FileStreamInput()
       
   110 {
       
   111     m_stream.Close();
       
   112 }
       
   113 
       
   114 StreamInput& FileStreamInput::operator>>(char& ch)
       
   115 {
       
   116     ch = m_stream.ReadInt8L();
       
   117     return *this;
       
   118 }
       
   119 
       
   120 
       
   121 StreamInput& FileStreamInput::operator>>(unsigned char& uch)
       
   122 {
       
   123     uch = m_stream.ReadUint8L();
       
   124     return *this;
       
   125 }
       
   126 
       
   127 
       
   128 StreamInput& FileStreamInput::operator>>(short& sh)
       
   129 {
       
   130     sh = m_stream.ReadInt16L();
       
   131     return *this;
       
   132 }
       
   133 
       
   134 
       
   135 StreamInput& FileStreamInput::operator>>(unsigned short& ush)
       
   136 {
       
   137     ush = m_stream.ReadUint16L();
       
   138     return *this;
       
   139 }
       
   140 
       
   141 
       
   142 StreamInput& FileStreamInput::operator>>(int& i)
       
   143 {
       
   144     i = m_stream.ReadInt32L();
       
   145     return *this;
       
   146 }
       
   147 
       
   148 
       
   149 StreamInput& FileStreamInput::operator>>(unsigned int& ui)
       
   150 {
       
   151     ui = m_stream.ReadUint32L();
       
   152     return *this;
       
   153 }
       
   154 
       
   155 
       
   156 StreamInput& FileStreamInput::operator>>(String& str)
       
   157 {
       
   158     int len = m_stream.ReadInt32L();
       
   159     UChar* data = new UChar[len];
       
   160     m_stream.ReadL(data, len);
       
   161     str.insert(data, len, 0);
       
   162     delete data;
       
   163     return *this;
       
   164 }
       
   165 
       
   166 
       
   167 StreamInput& FileStreamInput::operator>>(Streamable& o)
       
   168 {
       
   169     o.read(*this);
       
   170     return *this;
       
   171 }
       
   172 
       
   173 //------------------------------------------------------------------------------
       
   174 // TextFileStreamOutput
       
   175 //------------------------------------------------------------------------------
       
   176 
       
   177 TextFileStreamOutput::TextFileStreamOutput(const String& path) : m_isOpened(false)
       
   178 {
       
   179     if (m_stream.Replace(StaticObjectsContainer::instance()->fsSession(), path.des(), EFileWrite | EFileStream | EFileShareAny) == KErrNone)
       
   180         m_isOpened = true;
       
   181 }
       
   182 
       
   183 TextFileStreamOutput::~TextFileStreamOutput()
       
   184 {
       
   185     m_stream.Close();
       
   186 }
       
   187 
       
   188 StreamOutput& TextFileStreamOutput::operator<<(char ch)
       
   189 {
       
   190     m_data.append(String::number(ch));
       
   191     return *this;
       
   192 }
       
   193 
       
   194 StreamOutput& TextFileStreamOutput::operator<<(unsigned char ch)
       
   195 {
       
   196     m_data.append(String::number(ch));
       
   197     return *this;
       
   198 }
       
   199 
       
   200 StreamOutput& TextFileStreamOutput::operator<<(short sh)
       
   201 {
       
   202     m_data.append(String::number(sh));
       
   203     return *this;
       
   204 }
       
   205 
       
   206 StreamOutput& TextFileStreamOutput::operator<<(unsigned short ush)
       
   207 {
       
   208     m_data.append(String::number(ush));
       
   209     return *this;
       
   210 }
       
   211 
       
   212 StreamOutput& TextFileStreamOutput::operator<<(int i)
       
   213 {
       
   214     m_data.append(String::number(i));
       
   215     return *this;
       
   216 }
       
   217 
       
   218 StreamOutput& TextFileStreamOutput::operator<<(unsigned int ui)
       
   219 {
       
   220     m_data.append(String::number(ui));
       
   221     return *this;
       
   222 }
       
   223 
       
   224 StreamOutput& TextFileStreamOutput::operator<<(const String& str)
       
   225 {
       
   226     m_data.append(str);    
       
   227     return *this;
       
   228 }
       
   229 
       
   230 StreamOutput& TextFileStreamOutput::operator<<(const Streamable& o)
       
   231 {
       
   232     o.write(*this);
       
   233     return *this;
       
   234 }
       
   235 
       
   236 StreamOutput& TextFileStreamOutput::operator<<(const StreamEndOfLine&)
       
   237 {
       
   238     String str("\n");
       
   239     int len = str.length();
       
   240     const UChar* chs = str.characters();
       
   241     m_stream.WriteL((const TUint8*)(chs), len<<1);
       
   242     return *this;
       
   243 }
       
   244 
       
   245 
       
   246 
       
   247 }