Ejemplo n.º 1
0
inline ReturnOop ClassPathAccess::open_local_file(PathChar* path_name,
            Symbol* entry_symbol, const bool is_class_file JVM_TRAPS)
{
  const char separator_char = OsFile_separator_char;
  int pos = fn_strlen(path_name);

  path_name[pos++] = (PathChar)separator_char;
  for (int i=0; i<entry_symbol->length(); i++) {
      path_name[pos++] = (PathChar)entry_symbol->byte_at(i);
  }
  path_name[pos] = 0;
  if (is_class_file) {
    fn_strcat(path_name, FilePath::classfile_suffix);
  }

  if (separator_char != '/') {
    for(PathChar* tf = path_name; *tf; tf++) {
      if (*tf == (PathChar)'/') {
        *tf = (PathChar)separator_char;
      }
    }
  }

  OsFile_Handle handle = OsFile_open(path_name, "rb");
  if (handle == NULL) {
    return NULL;
  }

  int size = OsFile_length(handle);
  return FileDecoder::allocate(handle, 0, size, MUST_CLOSE_FILE
                               JVM_NO_CHECK_AT_BOTTOM);
}
Ejemplo n.º 2
0
bool BufferedFile::open(const PathChar *name, const char *mode)
{
  set_file_pointer(OsFile_open(name, mode));
  OsFile_Handle fh = file_pointer();
  set_file_size(fh == NULL ? 0 : OsFile_length(fh));
  return (fh != NULL);
}
Ejemplo n.º 3
0
// Create or retrieve a JarFileParser for the given JAR file.
// As a side effect, it might invalidate any previously obtained
// JarFileParser objects by closing their OsFile_handles.
ReturnOop JarFileParser::get(const JvmPathChar* jar_file_name1,
                             TypeArray * jar_file_name2,
                             bool enable_entry_cache JVM_TRAPS) {
  GUARANTEE((jar_file_name1 != NULL && jar_file_name2 == NULL) ||
            (jar_file_name1 == NULL && jar_file_name2 != NULL), "sanity");

  UsingFastOops fast_oops;
  JarFileParser::Fast parser = get_parser_from_cache(jar_file_name1,
                                                     jar_file_name2);
  if (parser.not_null()) {
    return parser;
  }

  if (jar_file_name1 && !OsFile_exists(jar_file_name1)) {
    return NULL;
  }
  if (jar_file_name2 && 
      !OsFile_exists((JvmPathChar *)jar_file_name2->byte_base_address())) {
    return NULL;
  }

  parser = Universe::new_mixed_oop(MixedOopDesc::Type_JarFileParser,
                                   JarFileParser::allocation_size(),
                                   JarFileParser::pointer_count()
                                   JVM_CHECK_0);
  TypeArray::Fast stored_name;
  if (jar_file_name1 != NULL) {
    size_t name_bytes = (fn_strlen(jar_file_name1)+1) * sizeof(JvmPathChar);
    stored_name = Universe::new_byte_array_raw(name_bytes JVM_CHECK_0);
    JvmPathChar *data = (JvmPathChar *)stored_name().byte_base_address();
    jvm_memcpy(data, jar_file_name1, name_bytes); // copy trailing NUL as well.
  } else {
    stored_name = jar_file_name2->obj();
  }


  BufferedFile::Fast bf = BufferedFile::allocate(JVM_SINGLE_ARG_CHECK_0);
  FileDescriptor::Fast desc = FileDescriptor::allocate(JVM_SINGLE_ARG_CHECK_0);

  OsFile_Handle fh = NULL;
  for (int pass=0; pass<2; pass++) {
    if (jar_file_name1) {
      fh = OsFile_open(jar_file_name1, "rb");
    } else {
      fh = OsFile_open((JvmPathChar *)jar_file_name2->byte_base_address(),
                       "rb");
    }
    if (fh != NULL) {
      break;
    }
    if (pass == 1 && fh == NULL) {
      // The system is running low on OsFile_Handles. Make sure we flush
      // the cache, and free all currently cached OsFile_Handles that belong
      // to other JAR files.
      flush_caches();
    }
  }
  if (fh == NULL) {
    return NULL;
  }

  desc().set_handle(fh);
  bf().set_file_pointer(fh);
  bf().set_file_size(fh == NULL ? 0 : OsFile_length(fh));
  parser().set_file_descriptor(&desc);
  parser().set_enable_entry_cache(enable_entry_cache);
  parser().set_pathname(&stored_name);
  parser().set_buffered_file(&bf);
  parser().set_timestamp(++_timestamp);

  if (!parser().find_end_of_central_header()) {
    // The jar file is corrupted. Stop parsing it.
    return NULL;
  }

  parser().save_parser_in_cache(JVM_SINGLE_ARG_MUST_SUCCEED);
  return parser;
}
Ejemplo n.º 4
0
size_t BufferedFile::length()
{
  return (size_t) OsFile_length(file_pointer());
}