private static FragmentData restoreFromByteArray (byte[] bytes) { DataInputStream dis = null; try { ByteArrayInputStream bis = new ByteArrayInputStream(bytes); dis = new DataInputStream(bis); FragmentData result = new FragmentData(); result.codedText = dis.readUTF(); result.codes = Code.stringToCodes(dis.readUTF()); return result; } catch ( IOException ex ) { return null; } finally { if ( dis != null ) { try { dis.close(); } catch ( IOException e ) {} // Swallow the error } } }
/** * Sets content of this TextContainer from a string created by {@link #contentToString(TextContainer)}. * @param data the string to process. * @return this TextConatiner. */ public TextContainer setContentFromString (String data) { this.setHasBeenSegmentedFlag((data.charAt(0)=='1')); String[] chunks = data.substring(1).split(PARTSEP2, 0); this.parts.clear(); for ( String chunk : chunks ) { int n1 = chunk.indexOf(PARTSEP1CHAR); int n2 = chunk.indexOf(PARTSEP1CHAR, n1+1); TextFragment tf = new TextFragment(chunk.substring(1, n1), Code.stringToCodes(chunk.substring(n1+1, n2))); this.parts.add((chunk.charAt(0)=='1') ? new Segment(chunk.substring(n2+1), tf) : new TextPart(tf)); } return this; }
int n = chunk.indexOf(PARTSEP1CHAR); try { TextFragment tf = new TextFragment(chunk.substring(1, n), Code.stringToCodes(codesParts[i])); if ( (chunk.charAt(0)=='1') ) { // It is a segment tc.parts.add(new Segment(chunk.substring(n+1), tf));
/** * Reads the next text fragment in the store. * @return the next text fragment in the store, or null if the end is reached. */ public TextFragment readNext () { try { String codedText = readLongString(); String tmp = readLongString(); TextFragment tf = new TextFragment(codedText, Code.stringToCodes(tmp)); return tf; } catch ( EOFException e ) { // Normal end return null; } catch ( IOException e ) { throw new OkapiException("Error while reading.", e); } }
tf = new TextFragment(); tf.setCodedText(result.getString(4), Code.stringToCodes(result.getString(5)), false); tu.setSourceContent(tf); tf = new TextFragment(); tf.setCodedText(result.getString(6), Code.stringToCodes(result.getString(7)), false); tu.setTargetContent(targetLocale, tf); tu.setName(result.getString(1));
qr.source = new TextFragment(); qr.source.setCodedText(result.getString(1), Code.stringToCodes(result.getString(2)), false); qr.target = new TextFragment(); qr.target.setCodedText(result.getString(3), Code.stringToCodes(result.getString(4)), false);
tmHitCandidates = getTopHits(query, metadata); for (TmHit tmHit : tmHitCandidates) { List<Code> tmCodes = Code.stringToCodes(getFieldValue(getIndexSearcher().doc( tmHit.getDocId()), TranslationUnitField.SOURCE_CODES)); String tmCodedText = getFieldValue(getIndexSearcher().doc(tmHit.getDocId()),
codes1.addAll(Code.stringToCodes(node1.code.getMergedData())); } else { codes1.add(node1.code); codes2.addAll(Code.stringToCodes(node2.code.getMergedData())); } else { codes2.add(node2.code);
tmHit.setScore(scoreDoc.score); List<Code> tmCodes = Code.stringToCodes(getFieldValue(getIndexSearcher().doc( tmHit.getDocId()), TranslationUnitField.SOURCE_CODES)); String tmCodedText = getFieldValue(getIndexSearcher().doc(tmHit.getDocId()),
private TranslationUnit createTranslationUnit(Document doc) { TextFragment frag = new TextFragment(); List<Code> codes = Code .stringToCodes(getFieldValue(doc, TranslationUnitField.SOURCE_CODES)); frag.setCodedText(getFieldValue(doc, TranslationUnitField.SOURCE_EXACT), codes, false); TranslationUnitVariant srcTuv = new TranslationUnitVariant(getLocaleValue(doc, TranslationUnitField.SOURCE_LANG), frag); frag = new TextFragment(); codes = Code.stringToCodes(getFieldValue(doc, TranslationUnitField.TARGET_CODES)); String codedText = getFieldValue(doc, TranslationUnitField.TARGET); frag.setCodedText(codedText == null ? "" : codedText, codes, false); TranslationUnitVariant trgTuv = new TranslationUnitVariant(getLocaleValue(doc, TranslationUnitField.TARGET_LANG), frag); TranslationUnit tu = new TranslationUnit(srcTuv, trgTuv); for (MetadataType type : MetadataType.values()) { tu.setMetadataValue(type, getFieldValue(doc, type)); } return tu; }
for (Code c : Code.stringToCodes(code.getMergedData())) { expandedCodes.append(c);
/** * Creates a {@link TranslationUnit} for a given document. * * @param doc * the document from which to create the new translation unit. * @param srcCodedText * the source coded text to re-use. * @param srcCodes * the source codes to re-use. * @return a new translation unit for the given document. */ private TranslationUnit createTranslationUnit(Document doc, String srcCodedText, List<Code> srcCodes) { TextFragment frag = new TextFragment(); frag.setCodedText(srcCodedText, srcCodes, false); TranslationUnitVariant srcTuv = new TranslationUnitVariant(getLocaleValue(doc, TranslationUnitField.SOURCE_LANG), frag); frag = new TextFragment(); List<Code> codes = Code .stringToCodes(getFieldValue(doc, TranslationUnitField.TARGET_CODES)); String codedText = getFieldValue(doc, TranslationUnitField.TARGET); frag.setCodedText(codedText == null ? "" : codedText, codes, false); TranslationUnitVariant trgTuv = new TranslationUnitVariant(getLocaleValue(doc, TranslationUnitField.TARGET_LANG), frag); TranslationUnit tu = new TranslationUnit(srcTuv, trgTuv); for (MetadataType type : MetadataType.values()) { tu.setMetadataValue(type, getFieldValue(doc, type)); } return tu; }