Revision 8948
Added by Jing Tao over 9 years ago
DocumentImpl.java | ||
---|---|---|
1498 | 1498 |
* @param accNumber |
1499 | 1499 |
* the document id which is used to name the output file |
1500 | 1500 |
*/ |
1501 |
private static void writeToFileSystem(String xml, String accNumber, String encoding) throws McdbException {
|
|
1501 |
private static void writeToFileSystem(byte[] xml, String accNumber) throws McdbException {
|
|
1502 | 1502 |
|
1503 | 1503 |
// write the document to disk |
1504 | 1504 |
String documentDir = null; |
... | ... | |
1528 | 1528 |
FileOutputStream fos = null; |
1529 | 1529 |
try { |
1530 | 1530 |
fos = new FileOutputStream(documentPath); |
1531 |
IOUtils.write(xml.getBytes(encoding), fos);
|
|
1531 |
IOUtils.write(xml, fos); |
|
1532 | 1532 |
|
1533 | 1533 |
fos.flush(); |
1534 | 1534 |
fos.close(); |
... | ... | |
2657 | 2657 |
|
2658 | 2658 |
public static String write(DBConnection conn, String xmlString, String pub, |
2659 | 2659 |
Reader dtd, String action, String docid, String user, |
2660 |
String[] groups, String ruleBase, boolean needValidation, boolean writeAccessRules) |
|
2660 |
String[] groups, String ruleBase, boolean needValidation, boolean writeAccessRules, byte[] xmlBytes)
|
|
2661 | 2661 |
throws Exception |
2662 | 2662 |
{ |
2663 | 2663 |
//this method will be called in handleUpdateOrInsert method |
... | ... | |
2665 | 2665 |
// get server location for this doc |
2666 | 2666 |
int serverLocation = getServerLocationNumber(docid); |
2667 | 2667 |
return write(conn, xmlString, pub, dtd, action, docid, user, groups, |
2668 |
serverLocation, false, ruleBase, needValidation, writeAccessRules); |
|
2668 |
serverLocation, false, ruleBase, needValidation, writeAccessRules, xmlBytes);
|
|
2669 | 2669 |
} |
2670 | 2670 |
|
2671 | 2671 |
/** |
... | ... | |
2702 | 2702 |
public static String write(DBConnection conn, String xmlString, String pub, |
2703 | 2703 |
Reader dtd, String action, String accnum, String user, |
2704 | 2704 |
String[] groups, int serverCode, boolean override, String ruleBase, |
2705 |
boolean needValidation, boolean writeAccessRules) throws Exception |
|
2705 |
boolean needValidation, boolean writeAccessRules, byte[] xmlBytes) throws Exception
|
|
2706 | 2706 |
{ |
2707 | 2707 |
// NEW - WHEN CLIENT ALWAYS PROVIDE ACCESSION NUMBER INCLUDING REV IN IT |
2708 | 2708 |
|
2709 | 2709 |
// Get the xml as a string so we can write to file later |
2710 | 2710 |
StringReader xmlReader = new StringReader(xmlString); |
2711 |
// detect encoding |
|
2712 |
XmlStreamReader xsr = null; |
|
2713 |
if(xmlBytes == null || xmlBytes.length == 0 ) { |
|
2714 |
xsr = new XmlStreamReader(new ByteArrayInputStream(xmlString.getBytes())); |
|
2715 |
} else { |
|
2716 |
xsr = new XmlStreamReader(new ByteArrayInputStream(xmlBytes)); |
|
2717 |
} |
|
2718 |
String encoding = xsr.getEncoding(); |
|
2719 |
//get the byte array from xmlString if the xmlbyte is null (this comes from metacat api) |
|
2720 |
if(xmlBytes == null || xmlBytes.length == 0) { |
|
2721 |
xmlBytes = xmlString.getBytes(encoding); |
|
2722 |
} |
|
2711 | 2723 |
|
2712 | 2724 |
logMetacat.debug("DocumentImpl.write - conn usage count before writing: " |
2713 | 2725 |
+ conn.getUsageCount()); |
... | ... | |
2767 | 2779 |
logReplication.info("lock granted for " + accnum |
2768 | 2780 |
+ " from " + server); |
2769 | 2781 |
|
2770 |
// detect encoding |
|
2771 |
XmlStreamReader xsr = new XmlStreamReader(new ByteArrayInputStream(xmlString.getBytes())); |
|
2772 |
String encoding = xsr.getEncoding(); |
|
2782 |
|
|
2773 | 2783 |
Vector<String>guidsToSync = new Vector<String>(); |
2774 | 2784 |
|
2775 | 2785 |
/* |
... | ... | |
2794 | 2804 |
|
2795 | 2805 |
//write the file to disk |
2796 | 2806 |
logMetacat.debug("DocumentImpl.write - Writing xml to file system"); |
2797 |
writeToFileSystem(xmlString, accnum, encoding);
|
|
2807 |
writeToFileSystem(xmlBytes, accnum);
|
|
2798 | 2808 |
|
2799 | 2809 |
// write to xml_node complete. start the indexing thread. |
2800 | 2810 |
addDocidToIndexingQueue(docid, rev); |
... | ... | |
2878 | 2888 |
} |
2879 | 2889 |
XMLReader parser = null; |
2880 | 2890 |
try { |
2881 |
// detect encoding |
|
2882 |
XmlStreamReader xsr = new XmlStreamReader(new ByteArrayInputStream(xmlString.getBytes())); |
|
2883 |
String encoding = xsr.getEncoding(); |
|
2891 |
|
|
2892 |
|
|
2884 | 2893 |
Vector<String>guidsToSync = new Vector<String>(); |
2885 | 2894 |
|
2886 | 2895 |
parser = initializeParser(conn, action, docid, xmlReader, rev, user, groups, |
... | ... | |
2900 | 2909 |
updateNodeValues(conn, docid); |
2901 | 2910 |
|
2902 | 2911 |
//write the file to disk |
2903 |
writeToFileSystem(xmlString, accnum, encoding);
|
|
2912 |
writeToFileSystem(xmlBytes, accnum);
|
|
2904 | 2913 |
|
2905 | 2914 |
addDocidToIndexingQueue(docid, rev); |
2906 | 2915 |
if (guidsToSync.size() > 0) { |
... | ... | |
3103 | 3112 |
conn.setAutoCommit(true); |
3104 | 3113 |
|
3105 | 3114 |
// Write the file to disk |
3106 |
writeToFileSystem(xmlString, accnum, encoding); |
|
3115 |
byte[] bytes = xmlString.getBytes(encoding); |
|
3116 |
writeToFileSystem(bytes, accnum); |
|
3107 | 3117 |
|
3108 | 3118 |
// write to xml_node complete. start the indexing thread. |
3109 | 3119 |
// this only for xml_documents |
Also available in: Unified diff
Write the input stream into the file system without alteration in dataone create and update methods.