1 /*****************************************************************************
5 * Creation date 12 Oct 2012
8 *****************************************************************************/
9 package test.splat.service;
11 import java.io.BufferedReader;
12 import java.io.DataInputStream;
14 import java.io.FileInputStream;
15 import java.io.FileNotFoundException;
16 import java.io.FileWriter;
17 import java.io.IOException;
18 import java.io.InputStreamReader;
19 import java.sql.SQLException;
20 import java.text.DecimalFormat;
21 import java.text.ParseException;
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.Calendar;
25 import java.util.Date;
26 import java.util.HashMap;
27 import java.util.List;
30 import org.splat.dal.bo.kernel.User;
31 import org.splat.dal.bo.som.ConvertsRelation;
32 import org.splat.dal.bo.som.Document;
33 import org.splat.dal.bo.som.DocumentType;
34 import org.splat.dal.bo.som.ProgressState;
35 import org.splat.dal.bo.som.ProjectElement;
36 import org.splat.dal.bo.som.Publication;
37 import org.splat.dal.bo.som.Scenario;
38 import org.splat.dal.bo.som.Study;
39 import org.splat.dal.bo.som.Document.Properties;
40 import org.splat.dal.dao.kernel.UserDAO;
41 import org.splat.dal.dao.som.Database;
42 import org.splat.dal.dao.som.ScenarioDAO;
43 import org.splat.dal.dao.som.StudyDAO;
44 import org.splat.exception.BusinessException;
45 import org.splat.kernel.InvalidPropertyException;
46 import org.splat.kernel.MissedPropertyException;
47 import org.splat.kernel.MultiplyDefinedException;
48 import org.splat.kernel.NotApplicableException;
49 import org.splat.log.AppLogger;
50 import org.splat.service.DocumentTypeService;
51 import org.splat.service.ProjectElementService;
52 import org.splat.service.PublicationService;
53 import org.splat.service.StepService;
54 import org.splat.service.StudyService;
55 import org.splat.service.technical.ProjectSettingsService;
56 import org.splat.service.technical.RepositoryService;
57 import org.splat.service.technical.ProjectSettingsService.Step;
58 import org.springframework.beans.factory.annotation.Autowired;
59 import org.springframework.beans.factory.annotation.Qualifier;
60 import org.springframework.orm.hibernate3.HibernateTemplate;
61 import org.testng.Assert;
62 import org.testng.annotations.Test;
64 import test.splat.common.BaseTest;
65 import test.splat.util.TestEntitiesGenerator;
68 * Test class for PublicationService.
70 * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
73 public class TestPublicationService extends BaseTest {
76 * Logger for the class.
78 private static final AppLogger LOG = AppLogger
79 .getLogger(TestPublicationService.class);
82 * The StudyDAO. Later injected by Spring.
85 @Qualifier("studyDAO")
86 private transient StudyDAO _studyDAO;
89 * The PublicationService. Later injected by Spring.
92 @Qualifier("publicationService")
93 private transient PublicationService _publicationService;
96 * The ProjectElementService. Later injected by Spring.
99 @Qualifier("projectElementService")
100 private transient ProjectElementService _projectElementService;
103 * The StepService. Later injected by Spring.
106 @Qualifier("stepService")
107 private transient StepService _stepService;
110 * The ProjectSettingsService. Later injected by Spring.
113 @Qualifier("projectSettings")
114 private transient ProjectSettingsService _projectSettings;
117 * The DocumentTypeService. Later injected by Spring.
120 @Qualifier("documentTypeService")
121 private transient DocumentTypeService _documentTypeService;
124 * The StudyService. Later injected by Spring.
127 @Qualifier("studyService")
128 private transient StudyService _studyService;
131 * The RepositoryService. Later injected by Spring.
134 @Qualifier("repositoryService")
135 private transient RepositoryService _repositoryService;
138 * The UserDAO. Later injected by Spring.
141 @Qualifier("userDAO")
142 private transient UserDAO _userDAO;
145 * The Scenario DAO. Later injected by Spring.
148 @Qualifier("scenarioDAO")
149 private transient ScenarioDAO _scenarioDAO;
152 * Create a persistent scenario for tests.
154 * @return a persistent scenario
155 * @throws InvalidPropertyException
156 * if an invalid property is used when creating objects
157 * @throws MultiplyDefinedException
158 * when trying to create an object with already existing id
159 * @throws MissedPropertyException
160 * if a mandatory property is not defined for an object to be created
161 * @throws IOException
162 * if document creation is failed
163 * @throws SQLException
164 * if project settings loading is failed
166 private Study createStudy() throws InvalidPropertyException,
167 MissedPropertyException, MultiplyDefinedException, IOException,
169 // Create a scenario for tests
170 HibernateTemplate ht = getHibernateTemplate();
172 Database.getInstance().reset();
173 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
174 // Load workflow customization
176 _projectSettings.configure("classpath:test/som.xml");
177 } catch (FileNotFoundException e) {
178 Assert.fail("Can't find som.xml: ", e);
180 List<Step> steps = _projectSettings.getAllSteps();
181 Assert.assertTrue(steps.size() > 0, "No steps are created.");
183 // Create a test user
184 User.Properties uprop = new User.Properties();
185 uprop.setUsername("TST_Username").setName("TST_SimanUnitTestsUser")
186 .setFirstName("TST_FirstName").setDisplayName("TST_test.user")
187 .addRole("TST_user").setMailAddress(
188 "noreply@salome-platform.org");
189 uprop.disableCheck();
190 User anAuthor = new User(uprop);
191 ht.saveOrUpdate(anAuthor);
193 // Create a test study
194 Study.Properties stprops = new Study.Properties().setReference(
195 "TST_SID_01").setTitle("TST_Study").setManager(anAuthor);
196 Study aStudy = new Study(stprops);
197 ht.saveOrUpdate(aStudy);
199 // Create a test scenario
200 Scenario.Properties sprops = new Scenario.Properties().setTitle(
201 "TST_Scenario").setManager(anAuthor).setOwnerStudy(aStudy);
202 Scenario aScenario = new Scenario(sprops);
203 aStudy.getScenariiList().add(aScenario);
204 ht.saveOrUpdate(anAuthor);
205 ht.saveOrUpdate(aStudy);
206 ht.saveOrUpdate(aScenario);
208 // Create documents for each scenario step
209 Document.Properties dprop = new Document.Properties().setAuthor(
210 anAuthor).setDate(new Date());
212 Publication usedPub = null;
213 Map<Long, Long> usedMap = new HashMap<Long, Long>();
214 for (int stepNum = 1; stepNum <= steps.size(); stepNum++) {
215 Step step = _projectSettings.getStep(stepNum);
216 LOG.debug("Create scenario step: " + stepNum);
217 ProjectElement projElem;
219 if (step.appliesTo(Study.class)) {
222 projElem = aScenario;
224 org.splat.som.Step aScStep = new org.splat.som.Step(step, projElem);
225 List<DocumentType> dtypes = _documentTypeService
226 .selectTypesOf(step);
227 if (dtypes.size() > 0) {
228 DocumentType dtype = dtypes.get(0);
229 // Create a document published in the scenario
230 // document<i>: document type[0] - first type used on the step
231 // <source-file>.brep
232 // <attached-file>.med
234 dprop.setName("document" + stepNum).setType(dtype);
235 if (step.getNumber() > 3) {
236 dprop.setFormat("med");
238 dprop.setFormat("py");
240 Publication pub = createDoc(projElem, aScStep, dprop, "med",
242 if (usedPub != null) {
243 pub.addDependency(usedPub);
244 LOG.debug("Add dependency: " + pub.value().getTitle()
245 + " from " + usedPub.value().getTitle());
246 ht.saveOrUpdate(pub.value());
249 usedMap.put(pub.getIndex(), usedPub.getIndex());
253 if (dtypes.size() <= 0) {
254 LOG.debug("No document types are found for scenario step " + i);
258 // Check that the scenario and its documents have been created correctly.
260 Assert.assertNotNull(ht.find("from Document"),
261 "No documents in the database.");
262 Assert.assertTrue(ht.find("from Document").size() > 0,
263 "No documents in the database.");
265 Assert.assertNotNull(ht.find("from Publication where owner="
266 + aScenario.getIndex()), "No publications in the database.");
268 ht.find("from Publication where owner=" + aScenario.getIndex())
269 .size() > 0, "No publications in the database.");
271 for (Publication p : (List<Publication>) ht
272 .find("from Publication where owner=" + aScenario.getIndex())) {
273 LOG.debug("Publication found: [id=" + p.getIndex() + ", owner="
274 + p.getOwner().getIndex() + ", doc=" + p.value().getIndex()
276 Assert.assertEquals(p.getOwner().getIndex(), aScenario.getIndex(),
277 "The publication was not attached to the scenario.");
280 // Remove the scenario from the current hibernate session.
282 // Check that the scenario is created in the database.
283 Scenario aScen = ht.load(Scenario.class, aScenario.getIndex());
284 Assert.assertNotNull(aScen, "Scenario was not saved in the database.");
285 Assert.assertTrue(aScen.getDocums().size() > 0,
286 "No publications in the scenario.");
288 Assert.assertTrue(i > 0,
289 "More then one document must be in the database");
291 // Check created uses relations
293 .assertTrue(usedMap.size() > 0,
294 "Uses relations must be created.");
295 boolean foundAny = false;
296 for (Long usingId : usedMap.keySet()) {
297 for (Publication pub : aScen.getDocums()) {
298 if (pub.getIndex() == usingId) {
299 boolean found = false;
300 for (Publication used : aScen.getDocums()) {
301 found = (used.getIndex() == usedMap.get(usingId));
307 for (Publication used : aStudy.getDocums()) {
308 found = (used.getIndex() == usedMap.get(usingId));
314 Assert.assertTrue(found,
315 "Uses relation was not created in the database.");
316 foundAny = foundAny || found;
320 Assert.assertTrue(foundAny,
321 "No Uses relation was created in the database.");
323 return aScenario.getOwnerStudy();
327 * Create a document published in the scenario. <BR>
329 * document type - type used on the step <BR>
330 * <source-file>.brep <BR>
331 * <attached-file>.med
334 * the scenario to add the document to
336 * scenario step where the document to be published
338 * document properties
339 * @param attachedFileExt
340 * extension of the secon attached (exported) file
342 * outdated document flag
343 * @return the publication of the created document
344 * @throws IOException
345 * @throws MultiplyDefinedException
346 * @throws InvalidPropertyException
347 * @throws MissedPropertyException
349 private Publication createDoc(final ProjectElement aScenario,
350 final org.splat.som.Step aScStep, final Properties dprop,
351 final String attachedFileExt, final boolean isOutdated)
352 throws MissedPropertyException, InvalidPropertyException,
353 MultiplyDefinedException, IOException {
354 // Create a document published in the scenario
355 // document<i>: document type - type used on the step
356 // <source-file>.brep
357 // <attached-file>.med
358 Publication pub = _stepService.createDocument(aScStep, dprop);
359 Assert.assertNotNull(pub.getOwner(),
360 "The publication must be attached to the scenario.");
361 Assert.assertEquals(pub.getOwner().getIndex(), aScenario.getIndex(),
362 "The publication was not attached to the scenario.");
368 HibernateTemplate ht = getHibernateTemplate();
369 ht.saveOrUpdate(pub);
372 ht.save(pub.value());
374 ht.saveOrUpdate(_publicationService.attach(pub, attachedFileExt));
380 * Test of generating a study document index.<BR>
381 * <B>Description :</B> <BR>
382 * <i>Create a study and try to generate the next document index.</i><BR>
383 * <B>Action : </B><BR>
384 * <i>1. call DAO's read method for an existing id.</i><BR>
385 * <B>Test data : </B><BR>
386 * <i>no input parameters</i><BR>
388 * <B>Outcome results:</B><BR>
391 * <li>The new index must be equal to the incremented old one and saved into the database<BR>
396 * @throws InvalidPropertyException
397 * if an invalid property is used when creating objects
398 * @throws MultiplyDefinedException
399 * when trying to create an object with already existing id
400 * @throws MissedPropertyException
401 * if a mandatory property is not defined for an object to be created
402 * @throws SQLException
403 * if test study creation is failed
404 * @throws IOException
405 * if test study creation is failed
406 * @throws ParseException
407 * @throws InterruptedException
408 * @throws NotApplicableException
412 public void testCreateDoc() throws InvalidPropertyException,
413 MissedPropertyException, MultiplyDefinedException, IOException,
414 SQLException, NotApplicableException, InterruptedException,
416 LOG.debug(">>>>> BEGIN testCreateDoc()");
417 startNestedTransaction();
419 HibernateTemplate ht = getHibernateTemplate();
420 Study aStudy = createStudy();
421 // Call DAO's create method for a good transient study.
422 Long id = aStudy.getIndex();
423 Assert.assertNotNull(id,
424 "Create method returns null instead of a new id.");
425 Assert.assertTrue(id > 0, "The new id is not a positive number.");
427 // Call DAO's get method for an existing id.
429 getHibernateTemplate().evict(aStudy);
430 getHibernateTemplate().clear();
431 Study aStudyFound = _studyDAO.get(id);
432 ht.evict(aStudyFound);
434 long userId = aStudyFound.getAuthor().getIndex();
435 org.splat.som.Step[] studySteps = _projectElementService
436 .getSteps(aStudyFound);
437 org.splat.som.Step[] scSteps = _projectElementService
438 .getSteps(aStudyFound.getScenarii()[0]);
440 List<org.splat.som.Step> steps = new ArrayList<org.splat.som.Step>();
441 steps.addAll(Arrays.asList(studySteps));
442 steps.addAll(Arrays.asList(scSteps));
443 steps.addAll(Arrays.asList(studySteps));
444 DecimalFormat tostring = new DecimalFormat(Document.suformat);
445 for (org.splat.som.Step step : steps) {
446 LOG.debug("Create a document for the step " + step.getNumber());
448 List<DocumentType> dtypes = _documentTypeService.selectTypesOf(step
450 if (dtypes.size() > 0) {
451 DocumentType dtype = dtypes.get(0);
452 int oldInd = ht.get(Study.class, aStudyFound.getIndex())
453 .getLastLocalIndex();
455 // Create a file in the download directory
456 String fname = "filename" + step.getNumber() + ".py";
457 String filePath = getDownloadPath(aStudyFound.getAuthor())
459 LOG.debug(step.getStep().getKey() + ": "
460 + step.getOwner().getClass().getSimpleName()
461 + ": Create test file: " + filePath);
462 FileWriter fw = new FileWriter(filePath);
464 .write("Simulation of filename.py file for creating a new document at "
468 Publication addoc = _publicationService.createDoc(aStudyFound
469 .getIndex(), step, dtype.getIndex(), userId, fname,
470 "tstdoc", ProgressState.inWORK, "", "", new Date(),
476 int ind = ht.get(Study.class, aStudyFound.getIndex())
477 .getLastLocalIndex();
479 LOG.debug("Previous index: " + oldInd + ", new index: " + ind);
480 Assert.assertEquals(ht.get(Study.class, aStudyFound.getIndex())
481 .getLastLocalIndex(), oldInd + 1,
482 "Incremented index must be saved in the database.");
483 aStudy = (Study) ht.find(
484 "from Study where rid = " + aStudyFound.getIndex())
486 Assert.assertEquals(aStudy.getLastLocalIndex(), oldInd + 1,
487 "Incremented index must be saved in the database.");
488 Assert.assertEquals(addoc.getSourceFile().getName(), tostring
489 .format(aStudy.getLastLocalIndex())
490 + "_" + fname, "The generated file name is incorrect.");
494 rollbackNestedTransaction();
495 LOG.debug(">>>>> END testCreateDoc()");
499 * Test of file attaching to a study document.<BR>
500 * <B>Description :</B> <BR>
501 * <i>Create a study and try to attach a new file to its each document.</i><BR>
502 * <B>Action : </B><BR>
503 * <i>1. call attach method for each document publication of the study.</i><BR>
504 * <B>Test data : </B><BR>
505 * <i>no input parameters</i><BR>
507 * <B>Outcome results:</B><BR>
510 * <li>The new ConvertsRelation and the new File object must be created in the database.<BR>
515 * @throws InvalidPropertyException
516 * if an invalid property is used when creating objects
517 * @throws MultiplyDefinedException
518 * when trying to create an object with already existing id
519 * @throws MissedPropertyException
520 * if a mandatory property is not defined for an object to be created
521 * @throws SQLException
522 * if test study creation is failed
523 * @throws IOException
524 * if test study creation is failed
525 * @throws ParseException
526 * @throws InterruptedException
527 * @throws NotApplicableException
531 public void testAttach() throws InvalidPropertyException,
532 MissedPropertyException, MultiplyDefinedException, IOException,
533 SQLException, NotApplicableException, InterruptedException,
535 LOG.debug(">>>>> BEGIN testAttach()");
536 startNestedTransaction();
538 HibernateTemplate ht = getHibernateTemplate();
539 Study aStudy = createStudy();
540 // Call DAO's create method for a good transient study.
541 Long id = aStudy.getIndex();
542 Assert.assertNotNull(id,
543 "Create method returns null instead of a new id.");
544 Assert.assertTrue(id > 0, "The new id is not a positive number.");
546 // Call DAO's get method for an existing id.
548 getHibernateTemplate().evict(aStudy);
549 getHibernateTemplate().clear();
550 Study aStudyFound = _studyDAO.get(id);
552 ht.evict(aStudyFound);
554 long userId = aStudyFound.getAuthor().getIndex();
555 org.splat.som.Step[] studySteps = _projectElementService
556 .getSteps(aStudyFound);
557 org.splat.som.Step[] scSteps = _projectElementService
558 .getSteps(aStudyFound.getScenarii()[0]);
560 List<org.splat.som.Step> steps = new ArrayList<org.splat.som.Step>();
561 steps.addAll(Arrays.asList(studySteps));
562 steps.addAll(Arrays.asList(scSteps));
563 steps.addAll(Arrays.asList(studySteps));
564 for (org.splat.som.Step step : steps) {
565 LOG.debug("Attach a new .py file to documents of the step "
566 + step.getNumber() + ": " + step.getStep().getKey() + ": "
567 + step.getOwner().getClass().getSimpleName());
569 for (Publication pub : step.getAllDocuments()) {
571 ht.evict(step.getOwner());
573 ht.evict(pub.value());
574 int nbConverts = ht.find("from ConvertsRelation").size();
575 int nbDocConverts = ht.find(
576 "from ConvertsRelation where owner="
577 + pub.value().getIndex()).size();
578 int nbFiles = ht.find("from File").size();
580 ConvertsRelation rel = _publicationService.attach(pub, "py");
584 Assert.assertNotNull(rel,
585 "Returned ConvertsRelation must not be null.");
587 .assertTrue(rel.isSaved(),
588 "Returned ConvertsRelation must be saved in the database.");
589 Assert.assertEquals(ht.find(
590 "from ConvertsRelation where owner="
591 + pub.value().getIndex()).size(),
593 "Number of created ConvertsRelations must be 1.");
594 Assert.assertEquals(ht.find("from ConvertsRelation").size(),
596 "Number of created ConvertsRelations must be 1.");
597 Assert.assertNotNull(rel.getTo(),
598 "Attached File must not be null.");
599 Assert.assertTrue(rel.isSaved(),
600 "Attached File must be saved in the database.");
604 "from File where rid="
605 + rel.getTo().getIndex())
606 .size(), 1, "Number of created File must be 1.");
607 Assert.assertEquals(ht.find("from File").size(), nbFiles + 1,
608 "Number of created Files must be 1.");
612 rollbackNestedTransaction();
613 LOG.debug(">>>>> END testAttach()");
617 * Get path to the user's downloads directory. The directory is created if it is not exist yet.
621 * @return absolute path to downloads directory followed by slash
623 private String getDownloadPath(final User user) {
624 // Prepare download directory
625 File tmpDir = _repositoryService.getDownloadDirectory(user);
626 if (!tmpDir.exists()) {
627 Assert.assertTrue(tmpDir.mkdir(),
628 "Can't create temporary directory: "
629 + tmpDir.getAbsolutePath());
632 return tmpDir.getAbsolutePath() + "/";
636 * Test testReplace method for a published document.<BR>
637 * <B>Description :</B> <BR>
638 * <i>Create a study and a scenario with documents and try to replace source files.<BR>
640 * <B>Action : </B><BR>
641 * <i>1. call the method for a document published in the study step.</i><BR>
642 * <i>2. call the method for a document published in the scenario step.</i><BR>
643 * <B>Test data : </B><BR>
644 * <i>no input parameters</i><BR>
645 * <i>no input parameters</i><BR>
647 * <B>Outcome results:</B><BR>
650 * <li>The document source file content in the study must be replaced.<BR>
652 * <li>The document source file content in the scenario must be replaced.<BR>
657 * @throws BusinessException
658 * if test data creation is failed
659 * @throws IOException
660 * if application configuration loading or test data creation is failed
661 * @throws SQLException
662 * if application configuration loading or test data creation is failed
665 public void testReplace() throws BusinessException, IOException,
667 LOG.debug(">>>>> BEGIN testReplace()");
668 startNestedTransaction();
670 HibernateTemplate ht = getHibernateTemplate();
672 Database.getInstance().reset();
673 _projectSettings.getAllSteps().clear(); // Clear config to be able to load it again
674 _projectSettings.configure("classpath:test/som.xml");
676 User goodUser = TestEntitiesGenerator.getTestUser("GoodUser");
677 _userDAO.create(goodUser);
679 // Create private study
680 Study aStudy = TestEntitiesGenerator.getTestStudy(goodUser);
681 aStudy.setTitle("0.This is private study");
682 Long studyId = _studyDAO.create(aStudy);
684 // Add a scenario to the study
685 Scenario scen = TestEntitiesGenerator.getTestScenario(aStudy);
686 Long scenId = _scenarioDAO.create(scen);
689 DocumentType dtype = _documentTypeService.selectType("minutes");
691 // Add documents to the first study activity
692 // Add a converts relations
693 Map<Integer, org.splat.som.Step> stSteps = _projectElementService
694 .getStepsMap(aStudy);
695 org.splat.som.Step aStep = stSteps.get(1);
696 Publication pub1 = addDoc(aStudy, aStep, "document1", dtype);
697 String format1 = pub1.value().getFormat();
702 // Add documents to the first scenario activity
703 scen = aStudy.getScenariiList().get(0);
704 Map<Integer, org.splat.som.Step> scSteps = _projectElementService
706 aStep = scSteps.get(2);
707 Publication spub1 = addDoc(scen, aStep, "sdocument1", dtype);
708 String format2 = spub1.value().getFormat();
711 Long id1 = pub1.value().getIndex(), id2 = spub1.value().getIndex();
714 ht.evict(scen.getOwnerStudy());
717 Assert.assertTrue(ht.find("from File").size() >= 2,
718 "Files were not created in the database.");
720 Date modifTime = Calendar.getInstance().getTime();
722 // TEST CALL: Replace a file in the study step
723 aStudy = _studyService.selectStudy(studyId);
724 Publication pub = aStudy.getDocums().toArray(new Publication[] {})[0];
725 File newFile = new File(getDownloadPath(goodUser) + "replaced1.ddd");
726 createFile(newFile.getAbsolutePath());
727 Assert.assertTrue(_publicationService.replace(pub, newFile, modifTime));
730 // TEST CALL: Replace a file in the scenario step
731 scen = aStudy.getScenariiList().get(0);
732 pub = scen.getDocums().toArray(new Publication[] {})[0];
733 newFile = new File(getDownloadPath(goodUser) + "replaced2.ddd");
734 createFile(newFile.getAbsolutePath());
735 Assert.assertTrue(_publicationService.replace(pub, newFile, modifTime));
739 // Remove milliseconds because they are lost after saving in the database
740 modifTime.setTime((modifTime.getTime() / 1000) * 1000);
742 Document doc = ht.get(Document.class, id1);
743 String txt = readFile(doc.getFile().asFile());
744 Assert.assertTrue(doc.getFile().getName().contains("_document1"));
745 Assert.assertEquals(doc.getFile().getFormat(), format1);
746 Assert.assertTrue(txt.contains("replaced1.ddd"));
747 Assert.assertEquals(doc.getLastModificationDate(), modifTime);
749 doc = ht.get(Document.class, id2);
750 txt = readFile(doc.getFile().asFile());
751 Assert.assertTrue(doc.getFile().getName().contains("_sdocument1"));
752 Assert.assertEquals(doc.getFile().getFormat(), format2);
753 Assert.assertTrue(txt.contains("replaced2.ddd"));
754 Assert.assertEquals(doc.getLastModificationDate(), modifTime);
756 rollbackNestedTransaction();
757 LOG.debug(">>>>> END testReplace()");
761 * Get file content as a string.
765 * @return the file content
766 * @throws IOException
767 * if reading is failed
769 private String readFile(final File f) throws IOException {
770 FileInputStream fstream = new FileInputStream(f);
771 // Get the object of DataInputStream
772 DataInputStream in = new DataInputStream(fstream);
773 BufferedReader br = new BufferedReader(new InputStreamReader(in));
774 StringBuffer res = new StringBuffer();
776 // Read File Line By Line
777 while ((str = br.readLine()) != null) {
780 // Close the input stream
782 return res.toString();