|
24 | 24 | import java.io.IOException; |
25 | 25 | import java.io.InputStream; |
26 | 26 | import java.io.OutputStream; |
| 27 | +import java.io.OutputStreamWriter; |
| 28 | +import java.io.RandomAccessFile; |
27 | 29 | import java.io.Reader; |
28 | 30 | import java.io.StringReader; |
| 31 | +import java.nio.ByteBuffer; |
| 32 | +import java.nio.channels.FileChannel; |
29 | 33 | import java.nio.charset.Charset; |
| 34 | +import java.nio.file.Path; |
30 | 35 | import java.util.ArrayList; |
31 | 36 | import java.util.List; |
32 | 37 |
|
@@ -60,6 +65,7 @@ public final class Utilities { |
60 | 65 | private static DocumentBuilderFactory factory; |
61 | 66 |
|
62 | 67 | private static DatatypeFactory datatypeFactory; |
| 68 | + static private int BUFFER_SIZE = 8192; |
63 | 69 |
|
64 | 70 | private static DocumentBuilderFactory getFactory() |
65 | 71 | throws ParserConfigurationException { |
@@ -669,4 +675,26 @@ static public DatatypeFactory getDatatypeFactory() { |
669 | 675 | } |
670 | 676 | return datatypeFactory; |
671 | 677 | } |
| 678 | + |
| 679 | + static public void write(InputStream in, Path path) { |
| 680 | + try { |
| 681 | + RandomAccessFile outFile = new RandomAccessFile(path.toString(), "rw"); |
| 682 | + FileChannel inChannel = outFile.getChannel(); |
| 683 | + byte[] buf = new byte[BUFFER_SIZE * 2]; |
| 684 | + ByteBuffer byteBuf; |
| 685 | + |
| 686 | + while (in.read(buf) != -1) { |
| 687 | + byteBuf = ByteBuffer.wrap(buf); |
| 688 | + byteBuf.flip(); |
| 689 | + inChannel.write(byteBuf); |
| 690 | + byteBuf.clear(); |
| 691 | + } |
| 692 | + outFile.close(); |
| 693 | + } catch (IOException e) { |
| 694 | + throw new MarkLogicIOException("Internal Exception occured."); |
| 695 | + } |
| 696 | + } |
| 697 | + |
| 698 | + static public void write(Reader in, OutputStreamWriter out) { } |
| 699 | + static public void write(Reader in, OutputStream out) {} |
672 | 700 | } |
0 commit comments