601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
|
return isAtEndOfStream;
}
- (size_t)_readNBytes: (size_t)length
intoBuffer: (char*)buffer
{
size_t retLength;
if (fileDescriptor == -1 || isAtEndOfStream)
@throw [OFReadFailedException newWithClass: isa
stream: self
requestedLength: length];
if ((retLength = read(fileDescriptor, buffer, length)) == 0)
isAtEndOfStream = YES;
return retLength;
}
- (size_t)_writeNBytes: (size_t)length
fromBuffer: (const char*)buffer
{
size_t retLength;
if (fileDescriptor == -1 || isAtEndOfStream ||
(retLength = write(fileDescriptor, buffer, length)) < length)
@throw [OFWriteFailedException newWithClass: isa
stream: self
requestedLength: length];
return retLength;
}
- (void)_seekToOffset: (off_t)offset
{
if (lseek(fileDescriptor, offset, SEEK_SET) == -1)
@throw [OFSeekFailedException newWithClass: isa
stream: self
offset: offset
whence: SEEK_SET];
}
- (off_t)_seekForwardWithOffset: (off_t)offset
{
off_t retOffset;
if ((retOffset = lseek(fileDescriptor, offset, SEEK_CUR)) == -1)
@throw [OFSeekFailedException newWithClass: isa
stream: self
offset: offset
whence: SEEK_CUR];
return retOffset;
}
- (off_t)_seekToOffsetRelativeToEnd: (off_t)offset
{
off_t retOffset;
if ((retOffset = lseek(fileDescriptor, offset, SEEK_END)) == -1)
@throw [OFSeekFailedException newWithClass: isa
stream: self
offset: offset
whence: SEEK_END];
return retOffset;
}
- (int)fileDescriptor
{
return fileDescriptor;
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
|
return isAtEndOfStream;
}
- (size_t)_readNBytes: (size_t)length
intoBuffer: (char*)buffer
{
size_t ret;
if (fileDescriptor == -1 || isAtEndOfStream)
@throw [OFReadFailedException newWithClass: isa
stream: self
requestedLength: length];
if ((ret = read(fileDescriptor, buffer, length)) == 0)
isAtEndOfStream = YES;
return ret;
}
- (size_t)_writeNBytes: (size_t)length
fromBuffer: (const char*)buffer
{
size_t ret;
if (fileDescriptor == -1 || isAtEndOfStream ||
(ret = write(fileDescriptor, buffer, length)) < length)
@throw [OFWriteFailedException newWithClass: isa
stream: self
requestedLength: length];
return ret;
}
- (void)_seekToOffset: (off_t)offset
{
if (lseek(fileDescriptor, offset, SEEK_SET) == -1)
@throw [OFSeekFailedException newWithClass: isa
stream: self
offset: offset
whence: SEEK_SET];
}
- (off_t)_seekForwardWithOffset: (off_t)offset
{
off_t ret;
if ((ret = lseek(fileDescriptor, offset, SEEK_CUR)) == -1)
@throw [OFSeekFailedException newWithClass: isa
stream: self
offset: offset
whence: SEEK_CUR];
return ret;
}
- (off_t)_seekToOffsetRelativeToEnd: (off_t)offset
{
off_t ret;
if ((ret = lseek(fileDescriptor, offset, SEEK_END)) == -1)
@throw [OFSeekFailedException newWithClass: isa
stream: self
offset: offset
whence: SEEK_END];
return ret;
}
- (int)fileDescriptor
{
return fileDescriptor;
}
|