An object with the same key already exist (DiscUtils)

  • (2 Pages)
  • +
  • 1
  • 2

18 Replies - 579 Views - Last Post: 24 July 2013 - 12:07 AM Rate Topic: -----

#16 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3183
  • View blog
  • Posts: 9,652
  • Joined: 05-May 12

Re: An object with the same key already exist (DiscUtils)

Posted 23 July 2013 - 09:04 AM

What is the underlying class the implements the stream referenced by _readStream? Perhaps its implementation is not efficient for the file sizes that you are dealing with.
Was This Post Helpful? 0
  • +
  • -

#17 Sparky414  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 20-July 13

Re: An object with the same key already exist (DiscUtils)

Posted 23 July 2013 - 09:52 AM

The underlying class is the Stream class, i suspect that the problem lies where the stream is populated. It must be "disposed early":

public override int Read(byte[] buffer, int offset, int count)
        {
            if (_position >= _length)
            {
                return 0;
            }

            int totalRead = 0;
            while (totalRead < count && _position < _length)
            {

                // If we need to find a new region, look for it
                if (_currentExtent == null)
                {
                    int idx = _extents.BinarySearch(new SearchExtent(_position), new ExtentRangeComparer());
                    if (idx >= 0)
                    {
                        BuilderExtent extent = _extents[idx];
                        extent.PrepareForRead();
                        _currentExtent = extent;
                    }
                }
                // If current region is outside the area of interest, clean it up
                if (_currentExtent != null && (_position < _currentExtent.Start || _position >= _currentExtent.Start + _currentExtent.Length))
                {
                	_currentExtent.DisposeReadState();
                	_currentExtent = null;
                }
                int numRead = 0;

                // If the block is outside any known extent, defer to base stream.
                if (_currentExtent == null)
                {
                    _baseStream.Position = _position;
                    BuilderExtent nextExtent = FindNext(_position);
                    if (nextExtent != null)
                    {
                        numRead = _baseStream.Read(buffer, offset + totalRead, (int)Math.Min(count - totalRead, nextExtent.Start - _position));
                    }
                    else
                    {
                        numRead = _baseStream.Read(buffer, offset + totalRead, count - totalRead);
                    }
                }
                else
                {
                    numRead = _currentExtent.Read(_position, buffer, offset + totalRead, count - totalRead);
                }

                _position += numRead;
                totalRead += numRead;
            }

            return totalRead;
        }public override int Read(byte[] buffer, int offset, int count)
        {
            if (_position >= _length)
            {
                return 0;
            }

            int totalRead = 0;
            while (totalRead < count && _position < _length)
            {

                // If we need to find a new region, look for it
                if (_currentExtent == null)
                {
                    int idx = _extents.BinarySearch(new SearchExtent(_position), new ExtentRangeComparer());
                    if (idx >= 0)
                    {
                        BuilderExtent extent = _extents[idx];
                        extent.PrepareForRead();
                        _currentExtent = extent;
                    }
                }
                // If current region is outside the area of interest, clean it up
                if (_currentExtent != null && (_position < _currentExtent.Start || _position >= _currentExtent.Start + _currentExtent.Length))
                {
                	_currentExtent.DisposeReadState();
                	_currentExtent = null;
                }
                int numRead = 0;

                // If the block is outside any known extent, defer to base stream.
                if (_currentExtent == null)
                {
                    _baseStream.Position = _position;
                    BuilderExtent nextExtent = FindNext(_position);
                    if (nextExtent != null)
                    {
                        numRead = _baseStream.Read(buffer, offset + totalRead, (int)Math.Min(count - totalRead, nextExtent.Start - _position));
                    }
                    else
                    {
                        numRead = _baseStream.Read(buffer, offset + totalRead, count - totalRead);
                    }
                }
                else
                {
                    numRead = _currentExtent.Read(_position, buffer, offset + totalRead, count - totalRead);
                }

                _position += numRead;
                totalRead += numRead;
            }

            return totalRead;
        }


I've stepped into this code again and again but i cannot see anything wrong. Do you happen to know any other way that i can make an iso and be able to report the proccess accurately (class / library)? although i would like to stick with DiscUtils because i think its a very good lib and i ve based my whole project on it.

I really appreciate your efforts. I didn't expect so much support :)
Was This Post Helpful? 0
  • +
  • -

#18 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3183
  • View blog
  • Posts: 9,652
  • Joined: 05-May 12

Re: An object with the same key already exist (DiscUtils)

Posted 23 July 2013 - 02:26 PM

In the other post, you highlighted that it was getting the stream position that was slow. Why are you looking at the Read() method now? Is it the Read() method that is slow and not the getter for the stream position?
Was This Post Helpful? 0
  • +
  • -

#19 Sparky414  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 20-July 13

Re: An object with the same key already exist (DiscUtils)

Posted 24 July 2013 - 12:07 AM

I looking at the Read() Method because this is where everything happens. Iam trying to figure out what is closing the stream "prematurely" in the first case and why it is slowing down in the second.

Build(string) -> Build(stream) -> Read()


Quote

Can not access a closed file.
at System.IO.__Error.FileNotOpen()
at System.IO.FileStream.get_Position()
at DiscUtils.Iso9660.FileExtent.Read(Int64 diskOffset, Byte[] block, Int32 of
fset, Int32 count) at c:\root\codeplex\discutils\src\Iso9660\FileExtent.cs: 53
at DiscUtils.BuiltStream.Read(Byte[] buffer, Int32 offset, Int32 count) at c
:\root\codeplex\discutils\src\BuiltStream.cs: 139
at DiscUtils.StreamBuilder.Build(Stream output) at c:\root\codeplex\discutil
s\src\StreamBuilder.cs:53
at DiscUtils.StreamBuilder.Build(String outputFile) at c:\root\codeplex\disc
utils\src\StreamBuilder.cs: 70
at isoReader.c_isoReader.AddtoISOByStream(String directory, String isoFile, C
ancellationToken ctoken) at d:\Code\isoReader\c_isoReader.cs:449

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2