There are 10 code examples for java.nio.charset.Charset.

The API names are highlighted below. You can use suckoo button to vote the code example(s) you like. The best code example will be ranked first next time. Thanks a lot for your feedback.

Project Name: codecover Package: org.codecover.eclipse.builder

Source Code: CodeCoverDebugListener.java (Click to view .java file)

Method Code:
vote
like

public void run(ActiveTSContainerInfo activeTSCInfo,IProgressMonitor monitor) throws CancelException {
  TestSessionContainer activeTSC=activeTSCInfo.getTestSessionContainer();
  MASTBuilder builder=new MASTBuilder(logger);
  TestSession testSession=activeTSC.createTestSession(testSessionName,testSessionComment,new Date());
  try {
    monitor.beginTask(this.getDescription(),3);
    try {
      CoverageLogParser logParser=new CoverageLogParser(coverageLogFile,coverageLogCharset);
      monitor.worked(1);
      CoverageResultLogReader coverageResultLogReader=new CoverageResultLogReader(testSession,builder);
      monitor.worked(1);
      logParser.CompilationUnit(coverageResultLogReader,activeTSC.getId());
      monitor.worked(1);
      coverageLogFile.delete();
    }
 catch (    IOException e) {
      logger.fatal("Error accessing the coverage" + " log file",e);
    }
catch (    WrongUIDException e) {
      logger.error("The coverage log file does" + " not fit to the session" + " container! Process aborted.",e);
    }
catch (    ParseException e) {
      logger.fatal("Error parsing the coverage log",e);
    }
  }
  finally {
    monitor.done();
  }
}
 

Project Name: codecover Package: org.codecover.eclipse.builder

Source Code: CodeCoverCompilationParticipant.java (Click to view .java file)

Method Code:
vote
like

private boolean isCodeUnchanged(HierarchyLevel code,BuildContext[] files,InstrumentableItemsManager instrumentableItemsManager){
  boolean result=true;
  for (  BuildContext buildContext : files) {
    final IFile file=buildContext.getFile();
    final IJavaElement compilationUnit=JavaCore.create(file);
    final HierarchyLevel codeFile=EclipseMASTLinkage.findSource(code,compilationUnit);
    final boolean instrument=instrumentableItemsManager.containsIPath(file.getFullPath());
    final boolean fileInTSC=codeFile != null;
    if (instrument && fileInTSC) {
      String mastText;
      Location mastLocation;
      mastLocation=codeFile.getLocation().getLocations().get(0);
      mastText=mastLocation.getFile().getContent();
      try {
        InputStream inStream=file.getContents();
        Charset charsetOfFile=Charset.forName(file.getCharset());
        String contentOfFile=FileTool.getContentFromStream(inStream,charsetOfFile);
        if (!mastText.equals(contentOfFile)) {
          eclipseLogger.debug(file.getName() + " has changed (break)");
          result=false;
          break;
        }
      }
 catch (      CoreException e) {
        e.printStackTrace();
        return false;
      }
catch (      IOException e) {
        e.printStackTrace();
        return false;
      }
    }
 else     if (instrument && !fileInTSC) {
      eclipseLogger.debug("was not found in the MAST (break)");
      result=false;
      break;
    }
 else     if (!instrument && fileInTSC) {
      result=false;
      break;
    }
  }
  return result;
}
 

Project Name: codecover Package: org.codecover.eclipse.utils

Source Code: EclipseMASTLinkage.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Read a whole file into a String.
 * @param filethe synchronized, existing, readable and local file
 * @returnthe contents of the file
 * @see IResource#isSynchronized(int)
 * @see IResource#isLocal(int)
 */
public static String getContent(IFile file){
  String contentOfFile=null;
  try {
    InputStream inStream=file.getContents();
    Charset charsetOfFile=Charset.forName(file.getCharset());
    contentOfFile=FileTool.getContentFromStream(inStream,charsetOfFile);
  }
 catch (  CoreException e) {
    boolean isSynchronized=false;
    boolean isLocal=false;
    try {
      isSynchronized=file.isSynchronized(IResource.DEPTH_ZERO);
      isLocal=file.isLocal(IResource.DEPTH_ZERO);
    }
 catch (    Exception ex) {
      CodeCoverPlugin.getDefault().getLogger().fatal("something is totally broken",ex);
    }
    if (!isSynchronized) {
      throw new IllegalArgumentException("file is not in sync");
    }
    if (!isLocal) {
      CodeCoverPlugin.getDefault().getLogger().error("Unexpected not local resource.  Please " + "file a bug with the whole message.",e);
      throw new IllegalArgumentException("file is not local");
    }
  }
catch (  IOException e) {
    CodeCoverPlugin.getDefault().getLogger().debug("Can't read: " + file.getFullPath().toOSString(),e);
    throw new IllegalArgumentException("File not readable.");
  }
  return contentOfFile;
}
 

Project Name: codecover Package: org.codecover.eclipse.views

Source Code: LiveNotificationView.java (Click to view .java file)

Method Code:
vote
like

public void run(ActiveTSContainerInfo activeTSCInfo,IProgressMonitor monitor) throws CancelException {
  TestSessionContainer activeTSC=activeTSCInfo.getTestSessionContainer();
  MASTBuilder builder=new MASTBuilder(logger);
  String testSessionName="livenotificationrun";
  String testSessionComment="";
  TestSession testSession=activeTSC.createTestSession(testSessionName,testSessionComment,new Date());
  try {
    monitor.beginTask(this.getDescription(),3);
    if (!testSessionName.equals(testSession.getName())) {
      String format=FORMAT_TEST_SESSION_ALREADY_EXSISTED;
      logger.warning(String.format(format,testSessionName,testSession.getName()));
    }
    try {
      CoverageLogParser logParser=new CoverageLogParser(logFile,MeasurementConstants.CHARSET);
      monitor.worked(1);
      CoverageResultLogReader coverageResultLogReader=new CoverageResultLogReader(testSession,builder);
      monitor.worked(1);
      logParser.CompilationUnit(coverageResultLogReader,activeTSC.getId());
      monitor.worked(1);
    }
 catch (    IOException e) {
      logger.fatal("Error accessing the coverage" + " log file",e);
    }
catch (    WrongUIDException e) {
      logger.error(ERROR_ENTERING_COVERAGE_LOG_INCOMPATIBLE,e);
    }
catch (    ParseException e) {
      logger.error(ERROR_ENTERING_THE_COVERAGE_LOG_READ_ERROR,e);
    }
  }
  finally {
    monitor.done();
  }
}
 

Project Name: codecover-instrumentation Package: org.codecover.instrumentation

Source Code: DefaultInstrumenterFactory.java (Click to view .java file)

Method Code:
vote
like

public void reset(){
  this.descriptor=null;
  this.charset=null;
  this.criteria=new TreeSet<Criterion>();
}
 

Project Name: codecover-instrumentation Package: org.codecover.instrumentation

Source Code: InstrumenterDescriptor.java (Click to view .java file)

Method Code:
vote
like

/** 
 * @param charsetNameThe name of the default charset for source files.
 * @throws IllegalCharsetNameExceptionIf no support for the named charset is available in this
 * instance of the Java virtual machine.
 * @see Charset#forName(String)
 */
protected void setDefaultCharset(String charsetName) throws IllegalCharsetNameException {
  if (charsetName == null) {
    throw new NullPointerException();
  }
  this.defaultCharset=Charset.forName(charsetName);
}
 

Project Name: codecover-instrumentation Package: org.codecover.instrumentation.measurement.parser

Source Code: CoverageLogParser.java (Click to view .java file)

Method Code:
vote
like

public CoverageLogParser(File source) throws IOException {
  this(source,CHARSET);
}
 

Project Name: codecover-model Package: org.codecover.model.utils

Source Code: SVNRevisionTool.java (Click to view .java file)

Method Code:
vote
like

/** 
 * This method is used to get SVN revision information while building CodeCover.<br>
 * <br>
 * Therefore the SVN revision and date are parsed, using the <code>RootDir</code>.
 * Then the <code>CodeCoverInfo</code>, which will be a copy of the{@link CodeCoverInfo}, will be updated by replacing the CodeCoverInfo.REVISION
 * and CodeCoverInfo.DATE in the source code by the revision and date got from
 * the svn working copy.  
 * @param args <code>{The path to the root directory,<br>
 * The file, which should be created}</code>
 * @throws IllegalArgumentException {@link #USAGE}.
 * @throws IOException While writing or reading the <code>CodeCoverInfo</code>
 * file.
 */
public static void main(String[] args) throws IOException {
  if (args.length != PARAM_COUNT) {
    throw new IllegalArgumentException(USAGE);
  }
  String rootDirPath=args[0];
  File rootDir=new File(rootDirPath).getAbsoluteFile();
  String codeCoverInfoPath=args[1];
  File codeCoverInfoFile=new File(codeCoverInfoPath).getAbsoluteFile();
  String contentOfInfoFile=FileTool.getContentFromFile(codeCoverInfoFile);
  try {
    SVNRevision rev=SVNRevision.WORKING;
    SVNInfo info=SVNClientManager.newInstance().getWCClient().doInfo(rootDir,rev);
    String revision=Long.toString(info.getRevision().getNumber());
    String date=info.getCommittedDate().toString();
    Matcher revisionMatcher=REVISION_PATTERN.matcher(contentOfInfoFile);
    if (!revisionMatcher.find()) {
      throw new RuntimeException("could not find the constant REVISION in " + codeCoverInfoPath);
    }
    contentOfInfoFile=revisionMatcher.replaceFirst("String REVISION = \"" + revision + "\";");
    Matcher dateMatcher=DATE_PATTERN.matcher(contentOfInfoFile);
    if (!dateMatcher.find()) {
      throw new RuntimeException("could not find the constant DATE in " + codeCoverInfoPath);
    }
    contentOfInfoFile=dateMatcher.replaceFirst("String DATE = \"" + date + "\";");
  }
 catch (  SVNException e) {
    System.err.println(e);
  }
  FileOutputStream fileOutputStream=new FileOutputStream(codeCoverInfoFile);
  OutputStreamWriter outputStreamWriter=new OutputStreamWriter(fileOutputStream,CodeCoverInfo.CODE_FILE_CHARSET);
  outputStreamWriter.write(contentOfInfoFile);
  outputStreamWriter.flush();
  outputStreamWriter.close();
}
 

Project Name: codecover-model Package: org.codecover.model.utils.file

Source Code: FileTool.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Copies a file <code>source</code> to the file <code>target</code> by
 * honoring charsets.<br>
 * <br>
 * If the <code>target</code> exists, it is overwritten, else it is created.
 * All parent folders of <code>target</code> are created before.  
 * @param source The source file to copy.
 * @param sourceCharset The charset of the source file.
 * @param target The destination, where to copy source.
 * @param targetCharset The charset of the target file.
 * @throws IOException If there occur read / write exceptions.
 */
public static void copy(File source,Charset sourceCharset,File target,Charset targetCharset) throws IOException {
  File absoluteSource=source.getAbsoluteFile();
  File absoluteTarget=target.getAbsoluteFile();
  absoluteTarget.getParentFile().mkdirs();
  FileInputStream fileInputStream=new FileInputStream(absoluteSource);
  InputStreamReader reader=new InputStreamReader(fileInputStream,sourceCharset);
  FileOutputStream fileOutputStream=new FileOutputStream(absoluteTarget);
  OutputStreamWriter writer=new OutputStreamWriter(fileOutputStream,targetCharset);
  try {
    char[] buffer=new char[COPY_BUFFER_SIZE];
    while (true) {
      int iReadSize=reader.read(buffer);
      if (iReadSize > 0) {
        writer.write(buffer,0,iReadSize);
      }
 else {
        break;
      }
    }
    writer.flush();
  }
  finally {
    reader.close();
    writer.close();
  }
}
 

Project Name: codecover-model Package: org.codecover.model.utils.file

Source Code: SourceTargetContainer.java (Click to view .java file)

Method Code:
vote
like

/** 
 * @return the charset of the file
 */
public Charset getCharset(){
  return this.charset;
}