Advertisement
Guest User

Untitled

a guest
Jun 25th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. class BufferFile : File
  2. {
  3.  
  4. byte[] buffer;
  5. int index = 0;
  6. BufferFile(String name, int N) : base(name)
  7. {
  8. buffer = new byte[N];
  9. }
  10.  
  11. public void write(byte b) //Zapisuje jeden byte do buffer'a
  12. {
  13. buffer[index++] = b;
  14. if (index == buffer.Length) writeBuffer();
  15. }
  16.  
  17. public void write(byte[] bytes) //Zapisuje do buffer'a
  18. {
  19. for(int n = 0; n < bytes.Length; n++)
  20. {
  21. write(bytes[n]);//Gdy buffer pełny, zapisze go do pliku. Następnie będzie nadpisywał
  22. }
  23. }
  24.  
  25. public void writeBuffer() //Zapisuje cały buffer do pliku
  26. {
  27. for(int n = 0; n < buffer.Length; n++)
  28. {
  29. write(buffer[n]);
  30. }
  31. index = 0;
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement