-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added CappedMemoryStream.cs to all project files
- Loading branch information
1 parent
8cf59d9
commit 1c530fb
Showing
4 changed files
with
34 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,35 @@ | ||
using System; | ||
using System.IO; | ||
|
||
namespace Jose; | ||
|
||
public class CappedMemoryStream : MemoryStream | ||
{ | ||
private readonly long maxCapacity; | ||
|
||
public CappedMemoryStream(long maxCapacity) | ||
{ | ||
this.maxCapacity = maxCapacity; | ||
} | ||
|
||
public override void Write(byte[] buffer, int offset, int count) | ||
{ | ||
if (Length + Math.Min(count, buffer.Length - offset) > maxCapacity) | ||
{ | ||
throw new CapacityExceededException("Exceeding maximum memory stream size."); | ||
} | ||
|
||
base.Write(buffer, offset, count); | ||
} | ||
|
||
public override void WriteByte(byte value) | ||
{ | ||
if (Length + 1 > maxCapacity) | ||
{ | ||
throw new CapacityExceededException("Exceeding maximum memory stream size."); | ||
} | ||
|
||
base.WriteByte(value); | ||
} | ||
namespace Jose | ||
This comment has been minimized.
Sorry, something went wrong. |
||
{ | ||
public class CappedMemoryStream : MemoryStream | ||
{ | ||
private readonly long maxCapacity; | ||
|
||
public CappedMemoryStream(long maxCapacity) | ||
{ | ||
this.maxCapacity = maxCapacity; | ||
} | ||
|
||
public override void Write(byte[] buffer, int offset, int count) | ||
{ | ||
if (Length + Math.Min(count, buffer.Length - offset) > maxCapacity) | ||
{ | ||
throw new CapacityExceededException("Exceeding maximum memory stream size."); | ||
} | ||
|
||
base.Write(buffer, offset, count); | ||
} | ||
|
||
public override void WriteByte(byte value) | ||
{ | ||
if (Length + 1 > maxCapacity) | ||
{ | ||
throw new CapacityExceededException("Exceeding maximum memory stream size."); | ||
} | ||
|
||
base.WriteByte(value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ah yes, of course - haven't worked with the older frameworks in a while