1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
31 // DVO: add zlib/ prefix
35 #include <zlib/zlib.h>
43 #include <osl/diagnose.h>
51 const int BUFSIZE
= 1024;
52 static uchar rBuf
[BUFSIZE
];
54 // HIODev abstract class
72 int HIODev::read1b(void *ptr
, int nmemb
)
74 uchar
*p
= (uchar
*) ptr
;
79 for (ii
= 0; ii
< nmemb
; ii
++)
81 p
[ii
] = sal::static_int_cast
<uchar
>(read1b());
89 int HIODev::read2b(void *ptr
, int nmemb
)
91 ushort
*p
= (ushort
*) ptr
;
96 for (ii
= 0; ii
< nmemb
; ii
++)
98 p
[ii
] = sal::static_int_cast
<uchar
>(read2b());
106 int HIODev::read4b(void *ptr
, int nmemb
)
108 ulong
*p
= (ulong
*) ptr
;
113 for (ii
= 0; ii
< nmemb
; ii
++)
124 HStreamIODev::HStreamIODev(HStream
& stream
):_stream(stream
)
130 HStreamIODev::~HStreamIODev()
136 void HStreamIODev::init()
143 bool HStreamIODev::open()
145 if (!(_stream
.available()))
151 void HStreamIODev::flush(void)
154 gz_flush(_gzfp
, Z_FINISH
);
158 void HStreamIODev::close(void)
160 /* Ç÷¯½ÃÇÑ ÈÄ ´Ý´Â´Ù. */
163 gz_close(_gzfp
); /* gz_close() calls stream_closeInput() */
165 _stream
.closeInput();
170 int HStreamIODev::state(void) const
177 bool HStreamIODev::setCompressed(bool flag
)
181 return 0 != (_gzfp
= gz_open(_stream
));
184 gz_flush(_gzfp
, Z_FINISH
);
194 #define GZREAD(ptr,len) (_gzfp?gz_read(_gzfp,ptr,len):0)
196 int HStreamIODev::read1b()
198 int res
= (compressed
) ? GZREAD(rBuf
, 1) : _stream
.readBytes(rBuf
, 1);
203 return (unsigned char) rBuf
[0];
207 int HStreamIODev::read2b()
209 int res
= (compressed
) ? GZREAD(rBuf
, 2) : _stream
.readBytes(rBuf
, 2);
214 return ((unsigned char) rBuf
[1] << 8 | (unsigned char) rBuf
[0]);
218 long HStreamIODev::read4b()
220 int res
= (compressed
) ? GZREAD(rBuf
, 4) : _stream
.readBytes(rBuf
, 4);
225 return ((unsigned char) rBuf
[3] << 24 | (unsigned char) rBuf
[2] << 16 |
226 (unsigned char) rBuf
[1] << 8 | (unsigned char) rBuf
[0]);
230 int HStreamIODev::readBlock(void *ptr
, int size
)
233 (compressed
) ? GZREAD(ptr
, size
) : _stream
.readBytes((byte
*) ptr
,
241 int HStreamIODev::skipBlock(int size
)
244 if( size
<= BUFSIZE
)
245 return GZREAD(rBuf
, size
);
249 if( remain
> BUFSIZE
)
250 remain
-= GZREAD(rBuf
, BUFSIZE
);
252 remain
-= GZREAD(rBuf
, remain
);
256 return size
- remain
;
259 return _stream
.skipBytes(size
);
263 HMemIODev::HMemIODev(char *s
, int len
)
271 HMemIODev::~HMemIODev()
277 void HMemIODev::init()
285 bool HMemIODev::open()
291 void HMemIODev::flush(void)
296 void HMemIODev::close(void)
301 int HMemIODev::state(void) const
310 bool HMemIODev::setCompressed(bool )
316 int HMemIODev::read1b()
325 int HMemIODev::read2b()
329 return ptr
[pos
- 1] << 8 | ptr
[pos
- 2];
335 long HMemIODev::read4b()
339 return DWORD(ptr
[pos
- 1] << 24 | ptr
[pos
- 2] << 16 |
340 ptr
[pos
- 3] << 8 | ptr
[pos
- 4]);
346 int HMemIODev::readBlock(void *p
, int size
)
348 if (length
< pos
+ size
)
350 memcpy(p
, ptr
+ pos
, size
);
356 int HMemIODev::skipBlock(int size
)
358 if (length
< pos
+ size
)
364 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */