2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #include <objc/objc-api.h>
25 #include "NGConcreteStreamFileHandle.h"
26 #include "NGStreamProtocols.h"
27 #include "NGStreamExceptions.h"
28 #include "NGBufferedStream.h"
30 @interface NGStream(FileHandleReset)
32 - (void)resetFileHandle;
36 @implementation NGConcreteStreamFileHandle
38 - (id)initWithStream:(id<NGStream>)_stream {
39 if ((self = [super init])) {
40 self->stream = [_stream retain];
46 if ([stream respondsToSelector:@selector(resetFileHandle)])
47 [(NGStream *)self->stream resetFileHandle];
48 [self->stream release];
54 - (id<NGStream>)stream {
58 /* NSFileHandle operations */
64 - (int)fileDescriptor {
65 if ([self->stream respondsToSelector:@selector(fileDescriptor)])
66 return [(id)self->stream fileDescriptor];
68 [self subclassResponsibility:_cmd];
75 - (void)synchronizeFile {
81 - (NSData *)readDataOfLength:(unsigned int)_length {
85 *(&buffer) = NGMallocAtomic(_length);
89 [stream safeReadBytes:buffer count:_length];
90 data = [[NSData alloc] initWithBytes:buffer length:_length];
93 if ([localException isKindOfClass:[NGEndOfStreamException class]]) {
94 data = [(NGEndOfStreamException *)localException readBytes];
96 data = data ? [data retain] : [[NSData alloc] init];
103 [localException raise];
113 return [data autorelease];
116 - (NSData *)readDataToEndOfFile {
117 NGBufferedStream *bs;
121 *(&data) = [NSMutableData dataWithCapacity:2048];
122 *(&bs) = [self->stream isKindOfClass:[NGBufferedStream class]]
123 ? [self->stream retain]
124 : [(NGBufferedStream *)[NGBufferedStream alloc]
125 initWithSource:self->stream];
129 unsigned got = [bs readBytes:buf count:2048];
130 [data appendBytes:buf length:got];
134 if (![localException isKindOfClass:[NGEndOfStreamException class]]) {
137 [localException raise];
141 [bs release]; bs = nil;
146 - (NSData *)availableData {
147 NSLog(@"NGConcreteStreamFileHandle(availableData) not implemented");
148 [self notImplemented:_cmd];
154 - (void)writeData:(NSData *)_data {
155 [self->stream safeWriteBytes:[_data bytes] count:[_data length]];
160 - (unsigned long long)seekToEndOfFile {
161 NSLog(@"NGConcreteStreamFileHandle(seekToEndOfFile) not implemented");
162 [self notImplemented:_cmd];
165 - (void)seekToFileOffset:(unsigned long long)_offset {
166 [(id<NGPositionableStream>)stream moveToLocation:_offset];
169 - (unsigned long long)offsetInFile {
170 NSLog(@"_NGConcreteFileStreamFileHandle(offsetInFile:) not implemented, abort");
171 [self notImplemented:_cmd];
175 /* asynchronous operations */
177 - (void)acceptConnectionInBackgroundAndNotify {
178 NSLog(@"NGConcreteStreamFileHandle(acceptConnectionInBackgroundAndNotify) "
180 [self notImplemented:_cmd];
182 - (void)acceptConnectionInBackgroundAndNotifyForModes:(NSArray *)_modes {
183 NSLog(@"NGConcreteStreamFileHandle(acceptConnectionInBackgroundAndNotifyForModes:) "
185 [self notImplemented:_cmd];
188 - (void)readInBackgroundAndNotify {
189 NSLog(@"NGConcreteStreamFileHandle(readInBackgroundAndNotify) not implemented");
190 [self notImplemented:_cmd];
192 - (void)readInBackgroundAndNotifyForModes:(NSArray *)_modes {
193 NSLog(@"NGConcreteStreamFileHandle(readInBackgroundAndNotifyForModes:) "
195 [self notImplemented:_cmd];
197 - (void)readToEndOfFileInBackgroundAndNotify {
198 NSLog(@"NGConcreteStreamFileHandle(readToEndOfFileInBackgroundAndNotify)"
200 [self notImplemented:_cmd];
202 - (void)readToEndOfFileInBackgroundAndNotifyForModes:(NSArray *)_modes {
203 NSLog(@"NGConcreteStreamFileHandle("
204 @"readToEndOfFileInBackgroundAndNotifyForModes:)"
206 [self notImplemented:_cmd];
209 - (void)waitForDataInBackgroundAndNotify {
210 NSLog(@"NGConcreteStreamFileHandle("
211 @"waitForDataInBackgroundAndNotify)"
213 [self notImplemented:_cmd];
215 - (void)waitForDataInBackgroundAndNotifyForModes:(NSArray *)_modes {
216 NSLog(@"NGConcreteStreamFileHandle("
217 @"waitForDataInBackgroundAndNotifyForModes:)"
219 [self notImplemented:_cmd];
222 @end /* NGConcreteStreamFileHandle */