List of usage examples for org.apache.commons.io Charsets UTF_8
Charset UTF_8
To view the source code for org.apache.commons.io Charsets UTF_8.
Click Source Link
Eight-bit Unicode Transformation Format.
From source file:org.silverpeas.test.jcr.JcrTest.java
/** * Creates a master document NODE into the JCR. * @param document//from w w w . ja va 2 s . com * @return * @throws Exception */ private SimpleDocument createDocumentIntoJcr(SimpleDocument document, String content) throws Exception { Session session = openJCRSession(); try { SimpleDocumentPK createdPk = getDocumentRepository().createDocument(session, document); session.save(); long contentSizeWritten = getDocumentRepository().storeContent(document, new ByteArrayInputStream(content.getBytes(Charsets.UTF_8))); assertThat(contentSizeWritten, is((long) content.length())); SimpleDocument createdDocument = getDocumentRepository().findDocumentById(session, createdPk, document.getLanguage()); assertThat(createdDocument, notNullValue()); assertThat(createdDocument.getOrder(), is(document.getOrder())); assertThat(createdDocument.getLanguage(), is(document.getLanguage())); return createdDocument; } finally { session.logout(); } }
From source file:org.silverpeas.test.jcr.JcrTest.java
/** * Creates a master document NODE into the JCR. * @param document/* ww w . j a v a2 s. c om*/ * @return * @throws Exception */ private SimpleDocument updateDocumentIntoJcr(SimpleDocument document, String content) throws Exception { assertThat(document.getPk(), notNullValue()); assertThat(document.getId(), not(isEmptyString())); assertThat(document.getInstanceId(), not(isEmptyString())); assertThat(document.getOldSilverpeasId(), greaterThan(0L)); Session session = openJCRSession(); try { Node documentNode = session.getNodeByIdentifier(document.getPk().getId()); converter.fillNode(document, documentNode); session.save(); if (content != null) { long contentSizeWritten = getDocumentRepository().storeContent(document, new ByteArrayInputStream(content.getBytes(Charsets.UTF_8))); assertThat(contentSizeWritten, is((long) content.length())); } SimpleDocument updatedDocument = getDocumentRepository().findDocumentById(session, document.getPk(), document.getLanguage()); assertThat(updatedDocument, notNullValue()); assertThat(updatedDocument.getLanguage(), is(document.getLanguage())); return updatedDocument; } finally { session.logout(); } }
From source file:org.silverpeas.util.Console.java
/** * Creates and open a console upon the specified file. All messages will be printed into the file. * The file will be created in the directory provided by the Configuration.getLogDir() method. * * @param fileName the name of the file into which the messages will be printed. * @param builderClass the class of the builder. * @throws IOException if an error occurs while creating the console. *//*w w w . j a v a 2s.c o m*/ public Console(final String fileName, final Class builderClass) throws IOException { logger = LoggerFactory.getLogger(builderClass); logFile = new File(Configuration.getLogDir(), fileName); FileUtils.forceMkdir(logFile.getParentFile()); logBuffer = new PrintWriter(new BufferedWriter( new OutputStreamWriter(new FileOutputStream(logFile.getAbsolutePath(), true), Charsets.UTF_8))); }
From source file:org.sonar.core.graph.graphson.GraphsonUtil.java
/** * Creates a vertex from GraphSON using settings supplied in the constructor. *//*from ww w . j a va 2 s .c o m*/ Vertex vertexFromJson(InputStream json) throws ParseException, IOException { return this.vertexFromJson((JSONObject) parser.parse(new InputStreamReader(json, Charsets.UTF_8))); }
From source file:org.sonar.core.graph.graphson.GraphsonUtil.java
/** * Creates an edge from GraphSON using settings supplied in the constructor. *//*ww w .j a v a 2s.c o m*/ Edge edgeFromJson(InputStream json, Vertex out, Vertex in) throws IOException, ParseException { return this.edgeFromJson((JSONObject) parser.parse(new InputStreamReader(json, Charsets.UTF_8)), out, in); }
From source file:org.sonar.cxx.sensors.visitors.CxxCpdVisitorTest.java
@Before @SuppressWarnings("unchecked") public void scanFile() { String dir = "src/test/resources/org/sonar/cxx/sensors"; File file = new File(dir, "/cpd.cc"); inputFile = new DefaultInputFile("moduleKey", file.getName()) .initMetadata(new FileMetadata().readMetadata(file, Charsets.UTF_8)); context = SensorContextTester.create(new File(dir)); context.fileSystem().add(inputFile); CxxCpdVisitor cxxCpdVisitor = new CxxCpdVisitor(context, true, true); CxxAstScanner.scanSingleFile(inputFile, context, TestUtils.mockCxxLanguage(), cxxCpdVisitor); }
From source file:org.sonar.cxx.sensors.visitors.CxxHighlighterTest.java
@Before @SuppressWarnings("unchecked") public void scanFile() { String dir = "src/test/resources/org/sonar/cxx/sensors"; file = new File(dir, "/highlighter.cc"); DefaultInputFile inputFile = new DefaultInputFile("moduleKey", file.getName()) .initMetadata(new FileMetadata().readMetadata(file, Charsets.UTF_8)); context = SensorContextTester.create(new File(dir)); context.fileSystem().add(inputFile); CxxHighlighterVisitor cxxHighlighter = new CxxHighlighterVisitor(context); CxxAstScanner.scanSingleFile(inputFile, context, TestUtils.mockCxxLanguage(), cxxHighlighter); }
From source file:org.sonar.cxx.visitors.CxxParseErrorLoggerVisitorTest.java
@Before @SuppressWarnings("unchecked") public void scanFile() { String dir = "src/test/resources/visitors"; file = new File(dir, "/syntaxerror.cc"); DefaultInputFile inputFile = new DefaultInputFile("moduleKey", file.getName()) .initMetadata(new FileMetadata().readMetadata(file, Charsets.UTF_8)); context = SensorContextTester.create(new File(dir)); context.fileSystem().add(inputFile); CxxAstScanner.scanSingleFile(inputFile, context); }
From source file:org.sonar.plugins.cxx.cpd.CxxCpdVisitorTest.java
@Before @SuppressWarnings("unchecked") public void scanFile() { String dir = "src/test/resources/org/sonar/plugins/cxx"; File file = new File(dir, "/cpd.cc"); inputFile = new DefaultInputFile("moduleKey", file.getName()) .initMetadata(new FileMetadata().readMetadata(file, Charsets.UTF_8)); context = SensorContextTester.create(new File(dir)); context.fileSystem().add(inputFile); CxxCpdVisitor cxxCpdVisitor = new CxxCpdVisitor(context, true, true); CxxAstScanner.scanSingleFile(inputFile, context, cxxCpdVisitor); }
From source file:org.sonar.plugins.cxx.highlighter.CxxHighlighterTest.java
@Before @SuppressWarnings("unchecked") public void scanFile() { String dir = "src/test/resources/org/sonar/plugins/cxx"; file = new File(dir, "/highlighter.cc"); DefaultInputFile inputFile = new DefaultInputFile("moduleKey", file.getName()) .initMetadata(new FileMetadata().readMetadata(file, Charsets.UTF_8)); context = SensorContextTester.create(new File(dir)); context.fileSystem().add(inputFile); CxxHighlighter cxxHighlighter = new CxxHighlighter(context); CxxAstScanner.scanSingleFile(inputFile, context, cxxHighlighter); }