Opens the import file.<p>

@throws IOException if the file could not be opened
438182
public void openFile() throws IOException {

        // get the import resource
        m_folder = new File(OpenCms.getSystemInfo().getAbsoluteRfsPathRelativeToWebInf(m_params.getPath()));

        // if it is a file it must be a zip-file
        if (m_folder.isFile()) {
            m_zipFile = new ZipFile(m_params.getPath());
            m_folder = null;
        }
    }
568269
protected void openFile() {

        try {
            FileAccess   fa  = isDump ? FileUtil.getDefaultInstance()
                                      : database.getFileAccess();
            OutputStream fos = fa.openOutputStreamElement(outFile);

            outDescriptor = fa.getFileSync(fos);
            fileStreamOut = new BufferedOutputStream(fos, 2 << 12);
        } catch (IOException e) {
            throw Error.error(ErrorCode.FILE_IO_ERROR,
                              ErrorCode.M_Message_Pair, new Object[] {
                e.toString(), outFile
            });
        }
    }
1282889
public InputStream getInputStream() throws IOException {
    InputStream is = this.servletContext.getResourceAsStream(this.path);
    if (is == null) { throw new FileNotFoundException("Could not open " + getDescription()); }
    return is;
  }
892881
public void importResource() {

        boolean resourceIdWasNull = false;

        try {
            if (m_throwable != null) {
                getReport().println(m_throwable);
                getReport().addError(m_throwable);

                CmsMessageContainer message = Messages.get().container(
                    Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_RESOURCES_0);
                if (LOG.isDebugEnabled()) {
                    LOG.debug(message.key(), m_throwable);
                }
                m_throwable = null;
                m_importACEs = false;
                m_resource = null;

                return;
            }

            // apply name translation and import path
            String translatedName = getCms().getRequestContext().addSiteRoot(
                m_parameters.getDestinationPath() + m_destination);

            boolean resourceImmutable = checkImmutable(translatedName);
            translatedName = getCms().getRequestContext().removeSiteRoot(translatedName);
            // if the resource is not immutable and not on the exclude list, import it
            if (!resourceImmutable) {
                // print out the information to the report
                getReport().print(Messages.get().container(Messages.RPT_IMPORTING_0), I_CmsReport.FORMAT_NOTE);
                getReport().print(
                    org.opencms.report.Messages.get().container(
                        org.opencms.report.Messages.RPT_ARGUMENT_1,
                        translatedName));
                getReport().print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0));

                boolean exists = getCms().existsResource(translatedName, CmsResourceFilter.ALL);

                byte[] content = null;
                // get the file content
                if (m_source != null) {
                    content = m_helper.getFileBytes(m_source);
                }
                int size = 0;
                if (content != null) {
                    size = content.length;
                }

                // get UUID for the structure
                if (m_structureId == null) {
                    // if null generate a new structure id
                    m_structureId = new CmsUUID();
                }

                // get UUIDs for the resource
                if ((m_resourceId == null) || (m_type.isFolder())) {
                    // folders get always a new resource UUID
                    m_resourceId = new CmsUUID();
                    resourceIdWasNull = true;
                }

                // create a new CmsResource
                CmsResource resource = new CmsResource(
                    m_structureId,
                    m_resourceId,
                    translatedName,
                    m_type.getTypeId(),
                    m_type.isFolder(),
                    m_flags,
                    getCms().getRequestContext().getCurrentProject().getUuid(),
                    CmsResource.STATE_NEW,
                    m_dateCreated,
                    m_userCreated,
                    m_dateLastModified,
                    m_userLastModified,
                    m_dateReleased,
                    m_dateExpired,
                    1,
                    size,
                    System.currentTimeMillis(),
                    0);

                if (m_properties == null) {
                    m_properties = new HashMap<String, CmsProperty>();
                }

                if (m_type.isFolder() || resourceIdWasNull || hasContentInVfsOrImport(resource)) {
                    // import this resource in the VFS
                    m_resource = getCms().importResource(
                        translatedName,
                        resource,
                        content,
                        new ArrayList<CmsProperty>(m_properties.values()));
                }

                // only set permissions if the resource did not exists or if the keep permissions flag is not set
                m_importACEs = (m_resource != null) && (!exists || !m_parameters.isKeepPermissions());

                if (m_resource != null) {
                    getReport().println(
                        org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0),
                        I_CmsReport.FORMAT_OK);

                    if (OpenCms.getResourceManager().getResourceType(
                        m_resource.getTypeId()) instanceof I_CmsLinkParseable) {
                        // store for later use
                        m_parseables.add(m_resource);
                    }
                    if (LOG.isInfoEnabled()) {
                        LOG.info(
                            Messages.get().getBundle().key(
                                Messages.LOG_IMPORTING_4,
                                new Object[] {
                                    String.valueOf(m_fileCounter),
                                    String.valueOf(m_totalFiles),
                                    translatedName,
                                    m_destination}));
                    }
                } else {
                    // resource import failed, since no CmsResource was created
                    getReport().print(Messages.get().container(Messages.RPT_SKIPPING_0), I_CmsReport.FORMAT_NOTE);
                    getReport().println(
                        org.opencms.report.Messages.get().container(
                            org.opencms.report.Messages.RPT_ARGUMENT_1,
                            translatedName));

                    if (LOG.isInfoEnabled()) {
                        LOG.info(
                            Messages.get().getBundle().key(
                                Messages.LOG_SKIPPING_3,
                                String.valueOf(m_fileCounter),
                                String.valueOf(m_totalFiles),
                                translatedName));
                    }
                }
            } else {
                m_resource = null;
                // skip the file import, just print out the information to the report
                getReport().print(Messages.get().container(Messages.RPT_SKIPPING_0), I_CmsReport.FORMAT_NOTE);
                getReport().println(
                    org.opencms.report.Messages.get().container(
                        org.opencms.report.Messages.RPT_ARGUMENT_1,
                        translatedName));

                if (LOG.isInfoEnabled()) {
                    LOG.info(
                        Messages.get().getBundle().key(
                            Messages.LOG_SKIPPING_3,
                            String.valueOf(m_fileCounter),
                            String.valueOf(m_totalFiles),
                            translatedName));
                }
                // do not import ACEs
                m_importACEs = false;
            }
        } catch (Exception e) {
            m_resource = null;
            m_importACEs = false;

            getReport().println(e);
            getReport().addError(e);

            CmsMessageContainer message = Messages.get().container(
                Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_RESOURCES_0);
            if (LOG.isDebugEnabled()) {
                LOG.debug(message.key(), e);
            }

            return;
        } finally {
            m_structureId = null;
            m_resourceId = null;
            m_destination = null;
            m_source = null;
            m_type = null;
            m_flags = 0;
            m_dateCreated = 0;
            m_dateLastModified = 0;
            m_dateReleased = CmsResource.DATE_RELEASED_DEFAULT;
            m_dateExpired = CmsResource.DATE_EXPIRED_DEFAULT;
            m_properties = null;
            m_throwable = null;
            m_aces = null;
            m_properties = null;
        }
    }
795419
private void openFiles() throws IOException {
        LogManager manager = LogManager.getLogManager();
        manager.checkPermission();
        if (count < 1) {
           throw new IllegalArgumentException("file count = " + count);
        }
        if (limit < 0) {
            limit = 0;
        }

        // We register our own ErrorManager during initialization
        // so we can record exceptions.
        InitializationErrorManager em = new InitializationErrorManager();
        setErrorManager(em);

        // Create a lock file.  This grants us exclusive access
        // to our set of output files, as long as we are alive.
        int unique = -1;
        for (;;) {
            unique++;
            if (unique > MAX_LOCKS) {
                throw new IOException("Couldn't get lock for " + pattern);
            }
            // Generate a lock file name from the "unique" int.
            lockFileName = generate(pattern, 0, unique).toString() + ".lck";
            // Now try to lock that filename.
            // Because some systems (e.g., Solaris) can only do file locks
            // between processes (and not within a process), we first check
            // if we ourself already have the file locked.
            synchronized(locks) {
                if (locks.get(lockFileName) != null) {
                    // We already own this lock, for a different FileHandler
                    // object.  Try again.
                    continue;
                }
                FileChannel fc;
                try {
                    lockStream = new FileOutputStream(lockFileName);
                    fc = lockStream.getChannel();
                } catch (IOException ix) {
                    // We got an IOException while trying to open the file.
                    // Try the next file.
                    continue;
                }
                boolean available;
                try {
                    available = fc.tryLock() != null;
                    // We got the lock OK.
                } catch (IOException ix) {
                    // We got an IOException while trying to get the lock.
                    // This normally indicates that locking is not supported
                    // on the target directory.  We have to proceed without
                    // getting a lock.   Drop through.
                    available = true;
                }
                if (available) {
                    // We got the lock.  Remember it.
                    locks.put(lockFileName, lockFileName);
                    break;
                }

                // We failed to get the lock.  Try next file.
                fc.close();
            }
        }

        files = new File[count];
        for (int i = 0; i < count; i++) {
            files[i] = generate(pattern, i, unique);
        }

        // Create the initial log file.
        if (append) {
            open(files[0], true);
        } else {
            rotate();
        }

        // Did we detect any exceptions during initialization?
        Exception ex = em.lastException;
        if (ex != null) {
            if (ex instanceof IOException) {
                throw (IOException) ex;
            } else if (ex instanceof SecurityException) {
                throw (SecurityException) ex;
            } else {
                throw new IOException("Exception: " + ex);
            }
        }

        // Install the normal default ErrorManager.
        setErrorManager(new ErrorManager());
    }
546899
public void importResource() {

        m_resourceIdWasNull = false;

        try {
            if (m_throwable != null) {
                getReport().println(m_throwable);
                getReport().addError(m_throwable);

                CmsMessageContainer message = Messages.get().container(
                    Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_RESOURCES_0);
                if (LOG.isDebugEnabled()) {
                    LOG.debug(message.key(), m_throwable);
                }
                m_throwable = null;
                m_importACEs = false;
                m_resource = null;

                return;
            }

            // apply name translation and import path
            String translatedName = getRequestContext().addSiteRoot(
                CmsStringUtil.joinPaths(m_parameters.getDestinationPath(), m_destination));

            boolean resourceImmutable = checkImmutable(translatedName);
            translatedName = getRequestContext().removeSiteRoot(translatedName);
            // if the resource is not immutable and not on the exclude list, import it
            if (!resourceImmutable) {
                // print out the information to the report
                getReport().print(Messages.get().container(Messages.RPT_IMPORTING_0), I_CmsReport.FORMAT_NOTE);
                getReport().print(
                    org.opencms.report.Messages.get().container(
                        org.opencms.report.Messages.RPT_ARGUMENT_1,
                        translatedName));
                getReport().print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0));

                boolean exists = getCms().existsResource(translatedName, CmsResourceFilter.ALL);

                byte[] content = null;
                // get the file content

                if (m_source != null) {
                    content = m_helper.getFileBytes(m_source);
                }
                int size = 0;
                if (content != null) {
                    size = content.length;
                }
                setDefaultsForEmptyResourceFields();
                // create a new CmsResource
                CmsResource resource = createResourceObjectFromFields(translatedName, size);

                if (m_resourceBuilder.getType().isFolder()
                    || m_resourceIdWasNull
                    || hasContentInVfsOrImport(resource)) {
                    // import this resource in the VFS
                    m_resource = getCms().importResource(
                        translatedName,
                        resource,
                        content,
                        new ArrayList<CmsProperty>(m_properties.values()));
                }

                if (m_resource != null) {
                    m_indexToStructureId.put(Integer.valueOf(m_fileCounter), m_resource.getStructureId());
                }

                // only set permissions if the resource did not exists or if the keep permissions flag is not set
                m_importACEs = (m_resource != null) && (!exists || !m_parameters.isKeepPermissions());

                if (m_resource != null) {
                    getReport().println(
                        org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0),
                        I_CmsReport.FORMAT_OK);

                    if (OpenCms.getResourceManager().getResourceType(
                        m_resource.getTypeId()) instanceof I_CmsLinkParseable) {
                        // store for later use
                        m_parseables.add(m_resource);
                    }
                    if (LOG.isInfoEnabled()) {
                        LOG.info(
                            Messages.get().getBundle().key(
                                Messages.LOG_IMPORTING_4,
                                new Object[] {
                                    String.valueOf(m_fileCounter),
                                    String.valueOf(m_totalFiles),
                                    translatedName,
                                    m_destination}));
                    }
                } else {
                    // resource import failed, since no CmsResource was created
                    getReport().print(Messages.get().container(Messages.RPT_SKIPPING_0), I_CmsReport.FORMAT_NOTE);
                    getReport().println(
                        org.opencms.report.Messages.get().container(
                            org.opencms.report.Messages.RPT_ARGUMENT_1,
                            translatedName));

                    if (LOG.isInfoEnabled()) {
                        LOG.info(
                            Messages.get().getBundle().key(
                                Messages.LOG_SKIPPING_3,
                                String.valueOf(m_fileCounter),
                                String.valueOf(m_totalFiles),
                                translatedName));
                    }
                }
            } else {
                m_resource = null;
                // skip the file import, just print out the information to the report
                getReport().print(Messages.get().container(Messages.RPT_SKIPPING_0), I_CmsReport.FORMAT_NOTE);
                getReport().println(
                    org.opencms.report.Messages.get().container(
                        org.opencms.report.Messages.RPT_ARGUMENT_1,
                        translatedName));

                if (LOG.isInfoEnabled()) {
                    LOG.info(
                        Messages.get().getBundle().key(
                            Messages.LOG_SKIPPING_3,
                            String.valueOf(m_fileCounter),
                            String.valueOf(m_totalFiles),
                            translatedName));
                }
                // do not import ACEs
                m_importACEs = false;
            }
        } catch (Exception e) {
            m_resource = null;
            m_importACEs = false;

            getReport().println(e);
            getReport().addError(e);

            CmsMessageContainer message = Messages.get().container(
                Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_RESOURCES_0);
            if (LOG.isDebugEnabled()) {
                LOG.debug(message.key(), e);
            }

            return;
        }
    }
1008857
public void read() throws IOException {
		long headerSize = header.getHeaderSize();
		int loadModuleSize = getLoadModuleSize();

		try (RandomAccessFile raf = new RandomAccessFile(file, "r")) {
			raf.seek(headerSize);
			loadModuleBytes = new byte[loadModuleSize];
			raf.readFully(loadModuleBytes);
		}
	}
168818
public void load(File file) throws IOException {
        _entryFile = file;
        Chronos c = new Chronos();
        ChannelReader in = new ChannelReader(file);

        try {
            in.open();

            // Read entry head
            long fileVersion = in.readLong();
            if (fileVersion != STORAGE_VERSION) {
                throw new RuntimeException("Wrong storage version " + fileVersion + " encounted in " + file.getAbsolutePath() + ". Version " + STORAGE_VERSION
                        + " expected.");
            }

            long minScnHead = in.readLong();
            long maxScnHead = in.readLong();
            int length = in.readInt();

            // Read entry body
            loadDataSection(in, length);

            // Read entry tail
            long minScnTail = in.readLong();
            long maxScnTail = in.readLong();

            if (minScnHead != minScnTail) {
                throw new IOException("min scns don't match: " + minScnHead + " vs " + minScnTail);
            }
            if (maxScnHead != maxScnTail) {
                throw new IOException("max scns don't match:" + maxScnHead + " vs " + maxScnTail);
            }

            _minScn = minScnHead;
            _maxScn = maxScnHead;

            if(_log.isInfoEnabled()) {
                _log.info("loaded entry: minScn=" + _minScn + " maxScn=" + _maxScn + " size=" + size() + " file=" + file.getName() + " in " + c.getElapsedTime());
            }
        } finally {
            in.close();
        }
    }
1254060
private void init() throws IOException {
        if (initialized.compareAndSet(false, true)) {
            log.debug("Init: {}", mode);
            // instance an executor for queue handling
            scheduledExecutorService = Executors.newScheduledThreadPool(schedulerThreadSize, new CustomizableThreadFactory("FileConsumerExecutor-"));
            // if the path is null, the consumer has been uninitialized
            if (path != null) {
                if (log.isDebugEnabled()) {
                    Path parent = path.getParent();
                    log.debug("Parent abs: {} dir: {}", parent.isAbsolute(), Files.isDirectory(parent));
                }
                if (IClientStream.MODE_APPEND.equals(mode)) {
                    if (Files.notExists(path)) {
                        throw new IOException("File to be appended doesnt exist, verify the record mode");
                    }
                    log.debug("Path: {}\nRead: {} write: {} size: {}", path, Files.isReadable(path), Files.isWritable(path), Files.size(path));
                    writer = new FLVWriter(path, true);
                } else if (IClientStream.MODE_RECORD.equals(mode)) {
                    try {
                        // delete existing file
                        if (Files.deleteIfExists(path)) {
                            log.debug("File deleted");
                        }
                        // ensure parent dirs exist
                        Files.createDirectories(path.getParent());
                        // create the file
                        path = Files.createFile(path);
                    } catch (IOException ioe) {
                        log.error("File creation error: {}", ioe);
                    }
                    if (!Files.isWritable(path)) {
                        throw new IOException("File is not writable");
                    }
                    log.debug("Path: {}\nRead: {} write: {}", path, Files.isReadable(path), Files.isWritable(path));
                    writer = new FLVWriter(path, false);
                    if (audioConfigurationTag != null) {
                        writer.writeTag(audioConfigurationTag);
                    }
                    if (videoConfigurationTag != null) {
                        writer.writeTag(videoConfigurationTag);
                        gotVideoKeyframe = true;
                    }
                } else {
                    //throw new IllegalStateException(String.format("Illegal mode type: %s", mode));
                    try {
                        // delete existing file since we're not recording nor appending
                        if (Files.deleteIfExists(path)) {
                            log.debug("File deleted");
                        }
                    } catch (IOException ioe) {
                        log.error("File creation error: {}", ioe);
                    }
                }
            } else {
                log.warn("Consumer is uninitialized");
            }
            log.debug("Init - complete");
        }
    }
99190
public BufferedReader openModelFile() {
	String filename = modelDir + File.separator + modelFile;
	BufferedReader fin = null;
	
	try {
	    fin = new BufferedReader(new InputStreamReader(new FileInputStream(filename), "UTF-8"));
	    
	} catch (IOException e) {
	    System.out.println(e.toString());
	    return null;
	}
	
	return fin;	
    }
863601
def open(self, *args, **kwargs):
        
        with io_error_compat():
            return io.open(self, *args, **kwargs)
1242609
public InputStream openInputStream()
    throws IOException
  {
    StreamSource indirectSource = _indirectSource;
    
    if (indirectSource != null) {
      return indirectSource.openInputStream();
    }
    
    TempOutputStream out = _out;
    if (out != null) {
      return out.openInputStreamNoFree();
    }
    
    // System.err.println("OpenInputStream: fail to open input stream for " + this);
    throw new IOException(L.l("{0}: no input stream is available",
                              this));
  }
728113
private void openInputStream(File txFile) throws IOException {
    int ioExceptionRetryCount = 0, logHeaderCorruptRetryCount = 0;
    
    LOG.info("Trying to load the edit log from " + txFile.getAbsolutePath());
    
    do {
      try {
        inputStream = new EditLogFileInputStream(txFile);
        editLogFilePosition = inputStream.getPosition();
        curStreamConsumed = false;
        curStreamFinished = false;
        readNullAfterStreamFinished = false;
        LOG.info("Successfully loaded the edits log from " +
            txFile.getAbsolutePath());
        break;
        
      } catch (LogHeaderCorruptException e1) {
        if (logHeaderCorruptRetryCount == LOG_HEADER_CORRUPT_RETRY_MAX) {
          LOG.error("Failed to load the edit log. No retries left.", e1);
          throw new IOException("Could not load the edit log");
        }
        logHeaderCorruptRetryCount ++;
        LOG.warn("Failed to load the edit log. Retry " +
            logHeaderCorruptRetryCount + " ...", e1);
        try {
          Thread.sleep(ioExceptionRetryCount * LOG_HEADER_CORRUPT_BASE_SLEEP);
        } catch (InterruptedException e) {
          throw new IOException(e);
        }
        
      } catch (IOException e2) {
        if (ioExceptionRetryCount == IO_EXCEPTION_RETRY_MAX) {
          LOG.error("Failed to load the edit log. No retries left.", e2);
          throw new IOException("Could not load the edit log");
        }
        ioExceptionRetryCount ++;
        LOG.warn("Failed to load the edit log. Retry " +
            ioExceptionRetryCount + " ...", e2);
        try {
          Thread.sleep(ioExceptionRetryCount * IO_EXCEPTION_BASE_SLEEP);
        } catch (InterruptedException e) {
          throw new IOException(e);
        }
      }
      
    } while (true);
  }
537643
public InputStream openInputStream()
    throws IOException
  {
    close();

    TempBuffer head = _head;
    _head = null;
    _tail = null;

    return new TempInputStream(head);
  }
655918
public ImportSection loadImportSection() throws IOException {
        Optional<ImportSection> idata = maybeLoadImportSection();
        return (ImportSection) getOrThrow(idata,
                "unable to load import section");
    }
198296
@Override
    public synchronized void open() throws IOException {
        if (_mode == Mode.OPEN) {
            return;
        }
        
        try {
            _addressArray.open();
            _segmentManager.open();
            _compactor.start();
            
            init();
            _mode = Mode.OPEN;
        } catch(Exception e) {
            _mode = Mode.CLOSED;
            _log.error("Failed to open", e);
            
            _compactor.shutdown();
            _compactor.clear();
            
            if (_addressArray.isOpen()) {
                _addressArray.close();
            }
            if (_segmentManager.isOpen()) {
                _segmentManager.close();
            }
            
            throw (e instanceof IOException) ? (IOException)e : new IOException(e);
        } finally {
            _log.info("mode=" + _mode);
        }
    }
1267305
@SuppressWarnings("unchecked")
    public void openFiles() throws FileLockException, IOException {
        files = new HeaderIndexFile[numberOfBuckets];
        cumulativeElementsPerFile = new int[numberOfBuckets];
        int lastfile = 0;
        String path = drums.getDatabaseDirectory();
        for (int i = 0; i < numberOfBuckets; i++) {
            String filename = path + "/" + drums.getHashFunction().getFilename(i);
            if (!new File(filename).exists()) {
                cumulativeElementsPerFile[i] = 0;
            } else {
                lastfile = i;
                files[i] = new HeaderIndexFile<Data>(filename, 10, drums.gp);
                cumulativeElementsPerFile[i] = (int) (files[i].getFilledUpFromContentStart() / elementSize);
            }
            if (i > 0) {
                cumulativeElementsPerFile[i] += cumulativeElementsPerFile[i - 1];
            }
        }

        destBuffer = ByteBuffer.allocate((int) files[lastfile].getChunkSize());
        filesAreOpened = true;
    }