Exemple #1
0
    public void Save()
    {
        if (!readOnly)
        {
            StreamWriter lFile = new StreamWriter(logFileName);

            lFile.WriteLine(Header.ToString());
            foreach (LogEntry l in Entries)
            {
                lFile.WriteLine(l.ToString());
            }

            lFile.Flush();
            lFile.Close();
        }
    }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel openForVersion(long version) throws java.io.IOException
        public override PhysicalLogVersionedStoreChannel OpenForVersion(long version)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.io.File fileToOpen = getLogFileForVersion(version);
            File fileToOpen = GetLogFileForVersion(version);

            if (!VersionExists(version))
            {
                throw new FileNotFoundException(format("File does not exist [%s]", fileToOpen.CanonicalPath));
            }

            StoreChannel rawChannel = null;

            try
            {
                rawChannel = OpenLogFileChannel(fileToOpen, OpenMode.READ);
                ByteBuffer buffer = ByteBuffer.allocate(LOG_HEADER_SIZE);
                LogHeader  header = readLogHeader(buffer, rawChannel, true, fileToOpen);
                if ((header == null) || (header.LogVersion != version))
                {
                    throw new System.InvalidOperationException(format("Unexpected log file header. Expected header version: %d, actual header: %s", version, header != null ? header.ToString() : "null header."));
                }
                return(new PhysicalLogVersionedStoreChannel(rawChannel, version, header.LogFormatVersion));
            }
            catch (FileNotFoundException cause)
            {
                throw ( FileNotFoundException )(new FileNotFoundException(format("File could not be opened [%s]", fileToOpen.CanonicalPath))).initCause(cause);
            }
            catch (Exception unexpectedError)
            {
                if (rawChannel != null)
                {
                    // If we managed to open the file before failing, then close the channel
                    try
                    {
                        rawChannel.close();
                    }
                    catch (IOException e)
                    {
                        unexpectedError.addSuppressed(e);
                    }
                }
                throw unexpectedError;
            }
        }