equal
deleted
inserted
replaced
1 /**************************************************************************** |
1 /**************************************************************************** |
2 ** |
2 ** |
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
4 ** All rights reserved. |
4 ** All rights reserved. |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
6 ** |
6 ** |
7 ** This file is part of the QtCore module of the Qt Toolkit. |
7 ** This file is part of the QtCore module of the Qt Toolkit. |
8 ** |
8 ** |
963 this, int(d->pos), int(d->buffer.size())); |
963 this, int(d->pos), int(d->buffer.size())); |
964 #endif |
964 #endif |
965 |
965 |
966 QByteArray result; |
966 QByteArray result; |
967 qint64 readBytes = 0; |
967 qint64 readBytes = 0; |
968 if (d->isSequential() || (readBytes = size()) == 0) { |
968 |
|
969 // flush internal read buffer |
|
970 if (!(d->openMode & Text) && !d->buffer.isEmpty()) { |
|
971 result = d->buffer.readAll(); |
|
972 readBytes = result.size(); |
|
973 d->pos += readBytes; |
|
974 } |
|
975 |
|
976 qint64 theSize; |
|
977 if (d->isSequential() || (theSize = size()) == 0) { |
969 // Size is unknown, read incrementally. |
978 // Size is unknown, read incrementally. |
970 qint64 readResult; |
979 qint64 readResult; |
971 do { |
980 do { |
972 result.resize(result.size() + QIODEVICE_BUFFERSIZE); |
981 result.resize(result.size() + QIODEVICE_BUFFERSIZE); |
973 readResult = read(result.data() + readBytes, result.size() - readBytes); |
982 readResult = read(result.data() + readBytes, result.size() - readBytes); |
975 readBytes += readResult; |
984 readBytes += readResult; |
976 } while (readResult > 0); |
985 } while (readResult > 0); |
977 } else { |
986 } else { |
978 // Read it all in one go. |
987 // Read it all in one go. |
979 // If resize fails, don't read anything. |
988 // If resize fails, don't read anything. |
980 result.resize(int(readBytes - d->pos)); |
989 result.resize(int(readBytes + theSize - d->pos)); |
981 readBytes = read(result.data(), result.size()); |
990 readBytes += read(result.data() + readBytes, result.size() - readBytes); |
982 } |
991 } |
983 |
992 |
984 if (readBytes <= 0) |
993 if (readBytes <= 0) |
985 result.clear(); |
994 result.clear(); |
986 else |
995 else |