📄 ramfile.cs
字号:
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
using System;
namespace Lucene.Net.Store
{
[Serializable]
public class RAMFile
{
private const long serialVersionUID = 1L;
// Direct read-only access to state supported for streams since a writing stream implies no other concurrent streams
internal System.Collections.ArrayList buffers = new System.Collections.ArrayList();
internal long length;
internal RAMDirectory directory;
internal long sizeInBytes; // Only maintained if in a directory; updates synchronized on directory
// This is publicly modifiable via Directory.touchFile(), so direct access not supported
private long lastModified = System.DateTime.Now.Ticks;
// File used as buffer, in no RAMDirectory
internal RAMFile()
{
}
internal RAMFile(RAMDirectory directory)
{
this.directory = directory;
}
// For non-stream access from thread that might be concurrent with writing
internal virtual long GetLength()
{
lock (this)
{
return length;
}
}
internal virtual void SetLength(long length)
{
lock (this)
{
this.length = length;
}
}
// For non-stream access from thread that might be concurrent with writing
internal virtual long GetLastModified()
{
lock (this)
{
return lastModified;
}
}
internal virtual void SetLastModified(long lastModified)
{
lock (this)
{
this.lastModified = lastModified;
}
}
internal byte[] AddBuffer(int size)
{
byte[] buffer = new byte[size];
if (directory != null)
lock (directory)
{
// Ensure addition of buffer and adjustment to directory size are atomic wrt directory
buffers.Add(buffer);
directory.sizeInBytes += size;
sizeInBytes += size;
}
else
buffers.Add(buffer);
return buffer;
}
// Only valid if in a directory
internal virtual long GetSizeInBytes()
{
lock (directory)
{
return sizeInBytes;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -