public void put(string key, byte[] value) { var file = mCache.newFile(key); FileOutputStream output = null; try { output = new FileOutputStream(file); output.Write(value); } catch (System.Exception ex) { VPNLog.d("ACache", ex.ToString()); } finally { if (output != null) { try { output.Flush(); output.Dispose(); } catch (IOException ex) { ex.PrintStackTrace(); } } mCache.put(file); } }
public void Execute() { ParseFileNames(); List <ArgumentOption> argumentOptions = GetArgumentOptions(); bool isArgumentTypesNotSimular = argumentOptions.Select(ao => ao.Type).Distinct().Count() != 1; if (isArgumentTypesNotSimular) { throw new ApplicationException("Arguments must be only input or output options"); } ArgumentType type = argumentOptions.First().Type; if (type == ArgumentType.Input) { argumentOptions.Reverse(); } IInputStream inputStream = new FileInputStream(_inputFileName); IOutputStream outputStream = new FileOutputStream(_outputFileName); DecorateByArgumentOptions(argumentOptions, ref inputStream, ref outputStream); WriteFromTo(inputStream, outputStream); inputStream.Dispose(); outputStream.Dispose(); }
private async Task RunAsync() { var buffer = _image.GetPlanes()[0].Buffer; byte[] bytes = new byte[buffer.Remaining()]; buffer.Get(bytes); using (var output = new FileOutputStream(_file)) { try { output.Write(bytes); output.Close(); output.Dispose(); bytes = null; buffer.Clear(); buffer.Dispose(); var mediaFile = new MediaFile(_file.AbsolutePath); await CrossMultiPictures.Current.ResizeAndRotateAsync(mediaFile, _mediaOptions, _currentRotation); CallBack?.Invoke(this, mediaFile); } catch (IOException ex) { ex.PrintStackTrace(); } finally { _image.Close(); } } }
public void CloseConnection() { Logger.LogInfo(nameof(Connection), nameof(CloseConnection), "called."); try { // Cancel the receive data task and dispose the rest. _TaskCancelTokenSource.Cancel(); _IsConnected = false; _OnConnectionClosed(); _InputStream.Dispose(); _OutputStream.Dispose(); _Accessory.Dispose(); _Manager.Dispose(); _OnDataReceived = null; _OnConnectionClosed = null; } catch (Exception ex) { Logger.LogError(ex); } }
public void WriteBlock_WriteAllFromArray_AllDataIsWritten() { // Arrange string fileName = GetTempFileName(); IOutputStream fileOutputStream = new FileOutputStream(fileName); var data = new byte[] { 1, 2, 3 }; // Act fileOutputStream.WriteBlock(data, size: ( uint )data.Length); fileOutputStream.Dispose(); // Assert Assert.True(IsEqualsDataFromFile(fileName, data)); }
public void WriteByte_ByteIsWritten() { // Arrange string fileName = GetTempFileName(); IOutputStream fileOutputStream = new FileOutputStream(fileName); byte data = 1; // Act fileOutputStream.WriteByte(data); fileOutputStream.Dispose(); // Assert Assert.True(IsEqualsDataFromFile(fileName, data)); }
public void WriteBlock_WriteFirstByteFromArray_WrittenOnlyOneByte() { // Arrange string fileName = GetTempFileName(); IOutputStream fileOutputStream = new FileOutputStream(fileName); var data = new byte[] { 1, 2, 3 }; var expectedWrittenData = new byte[] { 1 }; // Act fileOutputStream.WriteBlock(data, size: 1); fileOutputStream.Dispose(); // Assert Assert.True(IsEqualsDataFromFile(fileName, expectedWrittenData)); }
private static async Task <Java.IO.File> SavePhotoToDiskAsync(byte[] data, string directory) { Java.IO.File pictureFile; string photoFileName; using (var pictureFileDir = new Java.IO.File(directory)) { if (!pictureFileDir.Exists() && !pictureFileDir.Mkdirs()) { _logger.LogError("Can't create directory to save image"); return(null); } photoFileName = $"Picture-{Guid.NewGuid().ToString()}.jpg"; var imageFilePath = $"{pictureFileDir.Path}{Java.IO.File.Separator}{photoFileName}"; pictureFile = new Java.IO.File(imageFilePath); } FileOutputStream fileOutputStream = null; try { fileOutputStream = new FileOutputStream(pictureFile); await fileOutputStream.WriteAsync(data); } catch (Exception e) { _logger.LogError($"File {photoFileName} has not been saved: {e.Message}", e); } finally { fileOutputStream?.Close(); fileOutputStream?.Dispose(); } return(pictureFile); }