GetChannel() public method

public GetChannel ( ) : FileChannel
return FileChannel
Ejemplo n.º 1
0
		/// <exception cref="System.IO.IOException"></exception>
		private NGit.Storage.File.ReflogWriter Log(string refName, byte[] rec)
		{
			FilePath log = LogFor(refName);
			bool write = forceWrite || (IsLogAllRefUpdates() && ShouldAutoCreateLog(refName))
				 || log.IsFile();
			if (!write)
			{
				return this;
			}
			WriteConfig wc = GetRepository().GetConfig().Get(WriteConfig.KEY);
			FileOutputStream @out;
			try
			{
				@out = new FileOutputStream(log, true);
			}
			catch (FileNotFoundException err)
			{
				FilePath dir = log.GetParentFile();
				if (dir.Exists())
				{
					throw;
				}
				if (!dir.Mkdirs() && !dir.IsDirectory())
				{
					throw new IOException(MessageFormat.Format(JGitText.Get().cannotCreateDirectory, 
						dir));
				}
				@out = new FileOutputStream(log, true);
			}
			try
			{
				if (wc.GetFSyncRefFiles())
				{
					FileChannel fc = @out.GetChannel();
					ByteBuffer buf = ByteBuffer.Wrap(rec);
					while (0 < buf.Remaining())
					{
						fc.Write(buf);
					}
					fc.Force(true);
				}
				else
				{
					@out.Write(rec);
				}
			}
			finally
			{
				@out.Close();
			}
			return this;
		}
		/// <exception cref="System.IO.IOException"></exception>
		/// <exception cref="System.IO.FileNotFoundException"></exception>
		/// <exception cref="Sharpen.Error"></exception>
		private FilePath ToTemp(MessageDigest md, int type, long len, InputStream @is)
		{
			bool delete = true;
			FilePath tmp = NewTempFile();
			try
			{
				FileOutputStream fOut = new FileOutputStream(tmp);
				try
				{
					OutputStream @out = fOut;
					if (config.GetFSyncObjectFiles())
					{
						@out = Channels.NewOutputStream(fOut.GetChannel());
					}
					DeflaterOutputStream cOut = Compress(@out);
					DigestOutputStream dOut = new DigestOutputStream(cOut, md);
					WriteHeader(dOut, type, len);
					byte[] buf = Buffer();
					while (len > 0)
					{
						int n = @is.Read(buf, 0, (int)Math.Min(len, buf.Length));
						if (n <= 0)
						{
							throw ShortInput(len);
						}
						dOut.Write(buf, 0, n);
						len -= n;
					}
					dOut.Flush();
					cOut.Finish();
				}
				finally
				{
					if (config.GetFSyncObjectFiles())
					{
						fOut.GetChannel().Force(true);
					}
					fOut.Close();
				}
				delete = false;
				return tmp;
			}
			finally
			{
				if (delete)
				{
					FileUtils.Delete(tmp);
				}
			}
		}
Ejemplo n.º 3
0
		/// <exception cref="System.IO.IOException"></exception>
		private void WriteIdx()
		{
			Arrays.Sort(entries, 0, entryCount);
			IList<PackedObjectInfo> list = Arrays.AsList(entries);
			if (entryCount < entries.Length)
			{
				list = list.SubList(0, entryCount);
			}
			FileOutputStream os = new FileOutputStream(dstIdx);
			try
			{
				PackIndexWriter iw;
				if (outputVersion <= 0)
				{
					iw = PackIndexWriter.CreateOldestPossible(os, list);
				}
				else
				{
					iw = PackIndexWriter.CreateVersion(os, outputVersion);
				}
				iw.Write(list, packcsum);
				os.GetChannel().Force(true);
			}
			finally
			{
				os.Close();
			}
		}
		/// <exception cref="System.IO.IOException"></exception>
		private void WriteIdx()
		{
			IList<PackedObjectInfo> list = GetSortedObjectList(null);
			FileOutputStream os = new FileOutputStream(tmpIdx);
			try
			{
				PackIndexWriter iw;
				if (indexVersion <= 0)
				{
					iw = PackIndexWriter.CreateOldestPossible(os, list);
				}
				else
				{
					iw = PackIndexWriter.CreateVersion(os, indexVersion);
				}
				iw.Write(list, packHash);
				os.GetChannel().Force(true);
			}
			finally
			{
				os.Close();
			}
		}
Ejemplo n.º 5
0
		/// <exception cref="System.IO.IOException"></exception>
		/// <exception cref="System.IO.FileNotFoundException"></exception>
		private FilePath ToTemp(int type, byte[] buf, int pos, int len)
		{
			bool delete = true;
			FilePath tmp = NewTempFile();
			try
			{
				FileOutputStream fOut = new FileOutputStream(tmp);
				try
				{
					OutputStream @out = fOut;
					if (config.GetFSyncObjectFiles())
					{
						@out = Channels.NewOutputStream(fOut.GetChannel());
					}
					DeflaterOutputStream cOut = Compress(@out);
					WriteHeader(cOut, type, len);
					cOut.Write(buf, pos, len);
					cOut.Finish();
				}
				finally
				{
					if (config.GetFSyncObjectFiles())
					{
						fOut.GetChannel().Force(true);
					}
					fOut.Close();
				}
				delete = false;
				return tmp;
			}
			finally
			{
				if (delete)
				{
					FileUtils.Delete(tmp);
				}
			}
		}