use of java.io.RandomAccessFile in project intellij-community by JetBrains.
the class PatchApplyingRevertingTest method testRevertedWhenFileToDeleteIsProcessLocked.
@Test
public void testRevertedWhenFileToDeleteIsProcessLocked() throws Exception {
assumeTrue(UtilsTest.IS_WINDOWS);
Patch patch = PatchFileCreator.create(myPatchSpec, myFile, TEST_UI);
try (RandomAccessFile raf = new RandomAccessFile(new File(myOlderDir, "bin/idea.bat"), "rw")) {
// Lock the file. FileLock is not good here, because we need to prevent deletion.
int b = raf.read();
raf.seek(0);
raf.write(b);
PatchFileCreator.PreparationResult preparationResult = PatchFileCreator.prepareAndValidate(myFile, myOlderDir, TEST_UI);
Map<String, Long> original = patch.digestFiles(myOlderDir, Collections.emptyList(), false, TEST_UI);
File backup = getTempFile("backup");
PatchFileCreator.apply(preparationResult, new HashMap<>(), backup, TEST_UI);
assertEquals(original, patch.digestFiles(myOlderDir, Collections.emptyList(), false, TEST_UI));
}
}
use of java.io.RandomAccessFile in project intellij-community by JetBrains.
the class PatchApplyingRevertingTest method testApplyingWithModifiedCriticalFilesAndDifferentRoot.
@Test
public void testApplyingWithModifiedCriticalFilesAndDifferentRoot() throws Exception {
myPatchSpec.setStrict(true);
myPatchSpec.setRoot("lib/");
myPatchSpec.setCriticalFiles(Collections.singletonList("lib/annotations.jar"));
Patch patch = PatchFileCreator.create(myPatchSpec, myFile, TEST_UI);
try (RandomAccessFile raf = new RandomAccessFile(new File(myOlderDir, "lib/annotations.jar"), "rw")) {
raf.seek(20);
raf.write(42);
}
File toDir = new File(myOlderDir, "lib/");
assertAppliedAndRevertedCorrectly(patch, PatchFileCreator.prepareAndValidate(myFile, toDir, TEST_UI));
}
use of java.io.RandomAccessFile in project async-http-client by AsyncHttpClient.
the class ResumableRandomAccessFileListenerTest method testOnBytesReceivedBufferHasArray.
@Test
public void testOnBytesReceivedBufferHasArray() throws IOException {
RandomAccessFile file = PowerMockito.mock(RandomAccessFile.class);
ResumableRandomAccessFileListener listener = new ResumableRandomAccessFileListener(file);
byte[] array = new byte[] { 1, 2, 23, 33 };
ByteBuffer buf = ByteBuffer.wrap(array);
listener.onBytesReceived(buf);
verify(file).write(array, 0, 4);
}
use of java.io.RandomAccessFile in project android-bootstrap by AndroidBootstrap.
the class ImageUtils method getBitmap.
/**
* Get a bitmap from the image path
*
* @param imagePath
* @param sampleSize
* @return bitmap or null if read fails
*/
public static Bitmap getBitmap(final String imagePath, final int sampleSize) {
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inDither = false;
options.inSampleSize = sampleSize;
RandomAccessFile file = null;
try {
file = new RandomAccessFile(imagePath, "r");
return BitmapFactory.decodeFileDescriptor(file.getFD(), null, options);
} catch (IOException e) {
Timber.d(e, "Could not get cached bitmap.");
return null;
} finally {
if (file != null)
try {
file.close();
} catch (IOException e) {
Timber.d(e, "Could not get cached bitmap.");
}
}
}
use of java.io.RandomAccessFile in project android-bootstrap by AndroidBootstrap.
the class ImageUtils method getSize.
/**
* Get size of image
*
* @param imagePath
* @return size
*/
public static Point getSize(final String imagePath) {
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
RandomAccessFile file = null;
try {
file = new RandomAccessFile(imagePath, "r");
BitmapFactory.decodeFileDescriptor(file.getFD(), null, options);
return new Point(options.outWidth, options.outHeight);
} catch (final IOException e) {
Timber.d(e, "Could not get size.");
return null;
} finally {
if (file != null) {
try {
file.close();
} catch (final IOException e) {
Timber.d(e, "Could not get size.");
}
}
}
}
Aggregations