Package org.apache.kato.hprof.image

Source Code of org.apache.kato.hprof.image.ImageFactoryImpl

/*******************************************************************************
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*   http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package org.apache.kato.hprof.image;

import java.io.File;
import java.io.IOException;

import javax.tools.diagnostics.image.Image;
import javax.tools.diagnostics.image.ImageAddressSpace;
import javax.tools.diagnostics.image.ImageFactory;
import javax.tools.diagnostics.image.ImageProcess;
import javax.tools.diagnostics.runtime.ManagedRuntime;
import javax.tools.diagnostics.runtime.java.JavaRuntime;

import org.apache.kato.hprof.datalayer.HProfFactory;
import org.apache.kato.hprof.datalayer.HProfFile;

public class ImageFactoryImpl implements ImageFactory{

  private static String[] suffixes=new String[]{"hprof"};
  @Override
  public int getMajorVersion() {
   
    return 0;
  }

  @Override
  public int getMinorVersion() {
   
    return 1;
  }

  @Override
  public int getModificationLevel() {
   
    return 0;
  }

  @Override
  public Image getImage(File imageFile) throws IOException {
   
    return getImage(imageFile,null);
  }

  @Override
  public Image getImage(File imageFile, File metadata) throws IOException {
   
    if(imageFile==null) throw new IllegalArgumentException("image file is null");
    if(imageFile.exists()==false) throw new IllegalArgumentException("image file does not exist");
    HProfFile hprofFile=HProfFactory.createReader(imageFile);
   
    hprofFile.open();
    ImageImpl impl=new ImageImpl(hprofFile);
   
    return impl;
  }

  @Override
  public String[] getValidFileExtensions() {
    return suffixes;
  }
  @Override
  public JavaRuntime getJavaRuntime(File file) throws IOException {
     Image i=getImage(file);
     if(i==null) return null;
    
    for(ImageAddressSpace space:i.getAddressSpaces()) {
      ImageProcess process=space.getCurrentProcess();
      for(ManagedRuntime r : process.getRuntimes()) {
        if(r instanceof JavaRuntime) return (JavaRuntime) r;
      }
    }
    return null;
  }

}
TOP

Related Classes of org.apache.kato.hprof.image.ImageFactoryImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.