CloseShieldedInputStream.java 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.tools.dbinstaller.util;
  20. import java.io.IOException;
  21. import java.io.InputStream;
  22. /**
  23. * Prevent the underlying input stream to close.
  24. * @author Joe Cheng, Zoey76
  25. */
  26. public class CloseShieldedInputStream extends InputStream
  27. {
  28. private InputStream _in = null;
  29. /**
  30. * Instantiates a new close shielded input stream.
  31. * @param in the in
  32. */
  33. public CloseShieldedInputStream(InputStream in)
  34. {
  35. _in = in;
  36. }
  37. /**
  38. * {@inheritDoc}
  39. */
  40. @Override
  41. public void close()
  42. {
  43. _in = null;
  44. }
  45. /**
  46. * {@inheritDoc}
  47. */
  48. @Override
  49. public int read() throws IOException
  50. {
  51. if (_in == null)
  52. {
  53. throw new IOException("Stream is null!");
  54. }
  55. return _in.read();
  56. }
  57. /**
  58. * {@inheritDoc}
  59. */
  60. @Override
  61. public int read(byte b[]) throws IOException
  62. {
  63. if (_in == null)
  64. {
  65. throw new IOException("Stream is null!");
  66. }
  67. return _in.read(b);
  68. }
  69. /**
  70. * {@inheritDoc}
  71. */
  72. @Override
  73. public int read(byte b[], int off, int len) throws IOException
  74. {
  75. if (_in == null)
  76. {
  77. throw new IOException("Stream is null!");
  78. }
  79. return _in.read(b, off, len);
  80. }
  81. /**
  82. * {@inheritDoc}
  83. */
  84. @Override
  85. public long skip(long n) throws IOException
  86. {
  87. if (_in == null)
  88. {
  89. throw new IOException("Stream is null!");
  90. }
  91. return _in.skip(n);
  92. }
  93. /**
  94. * {@inheritDoc}
  95. */
  96. @Override
  97. public synchronized void mark(int readlimit)
  98. {
  99. if (_in != null)
  100. {
  101. _in.mark(readlimit);
  102. }
  103. }
  104. /**
  105. * {@inheritDoc}
  106. */
  107. @Override
  108. public boolean markSupported()
  109. {
  110. if (_in == null)
  111. {
  112. return false;
  113. }
  114. return _in.markSupported();
  115. }
  116. /**
  117. * {@inheritDoc}
  118. */
  119. @Override
  120. public synchronized void reset() throws IOException
  121. {
  122. if (_in == null)
  123. {
  124. throw new IOException("Stream is null!");
  125. }
  126. _in.reset();
  127. }
  128. /**
  129. * Gets the underlying stream.
  130. * @return the underlying stream
  131. */
  132. public InputStream getUnderlyingStream()
  133. {
  134. return _in;
  135. }
  136. }