Java 类org.springframework.boot.loader.data.RandomAccessData.ResourceAccess 实例源码

项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:JarFile.java   
@Override
public Manifest getManifest() throws IOException {
    Manifest manifest = (this.manifest == null ? null : this.manifest.get());
    if (manifest == null) {
        if (this.type == JarFileType.NESTED_DIRECTORY) {
            manifest = new JarFile(this.getRootJarFile()).getManifest();
        }
        else {
            InputStream inputStream = getInputStream(MANIFEST_NAME,
                    ResourceAccess.ONCE);
            if (inputStream == null) {
                return null;
            }
            try {
                manifest = new Manifest(inputStream);
            }
            finally {
                inputStream.close();
            }
        }
        this.manifest = new SoftReference<Manifest>(manifest);
    }
    return manifest;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:JarFile.java   
void setupEntryCertificates(JarEntry entry) {
    // Fallback to JarInputStream to obtain certificates, not fast but hopefully not
    // happening that often.
    try {
        JarInputStream inputStream = new JarInputStream(
                getData().getInputStream(ResourceAccess.ONCE));
        try {
            java.util.jar.JarEntry certEntry = inputStream.getNextJarEntry();
            while (certEntry != null) {
                inputStream.closeEntry();
                if (entry.getName().equals(certEntry.getName())) {
                    setCertificates(entry, certEntry);
                }
                setCertificates(getJarEntry(certEntry.getName()), certEntry);
                certEntry = inputStream.getNextJarEntry();
            }
        }
        finally {
            inputStream.close();
        }
    }
    catch (IOException ex) {
        throw new IllegalStateException(ex);
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:JarFileArchive.java   
private void unpack(JarEntry entry, File file) throws IOException {
    InputStream inputStream = this.jarFile.getInputStream(entry, ResourceAccess.ONCE);
    try {
        OutputStream outputStream = new FileOutputStream(file);
        try {
            byte[] buffer = new byte[BUFFER_SIZE];
            int bytesRead = -1;
            while ((bytesRead = inputStream.read(buffer)) != -1) {
                outputStream.write(buffer, 0, bytesRead);
            }
            outputStream.flush();
        }
        finally {
            outputStream.close();
        }
    }
    finally {
        inputStream.close();
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:RandomAccessDataFileTests.java   
@Test
public void concurrentReads() throws Exception {
    ExecutorService executorService = Executors.newFixedThreadPool(20);
    List<Future<Boolean>> results = new ArrayList<Future<Boolean>>();
    for (int i = 0; i < 100; i++) {
        results.add(executorService.submit(new Callable<Boolean>() {

            @Override
            public Boolean call() throws Exception {
                InputStream subsectionInputStream = RandomAccessDataFileTests.this.file
                        .getSubsection(0, 256)
                        .getInputStream(ResourceAccess.PER_READ);
                byte[] b = new byte[256];
                subsectionInputStream.read(b);
                return Arrays.equals(b, BYTES);
            }
        }));
    }
    for (Future<Boolean> future : results) {
        assertThat(future.get()).isTrue();
    }
}
项目:spring-boot-concourse    文件:JarFile.java   
@Override
public Manifest getManifest() throws IOException {
    Manifest manifest = (this.manifest == null ? null : this.manifest.get());
    if (manifest == null) {
        if (this.type == JarFileType.NESTED_DIRECTORY) {
            manifest = new JarFile(this.getRootJarFile()).getManifest();
        }
        else {
            InputStream inputStream = getInputStream(MANIFEST_NAME,
                    ResourceAccess.ONCE);
            if (inputStream == null) {
                return null;
            }
            try {
                manifest = new Manifest(inputStream);
            }
            finally {
                inputStream.close();
            }
        }
        this.manifest = new SoftReference<Manifest>(manifest);
    }
    return manifest;
}
项目:spring-boot-concourse    文件:JarFile.java   
void setupEntryCertificates(JarEntry entry) {
    // Fallback to JarInputStream to obtain certificates, not fast but hopefully not
    // happening that often.
    try {
        JarInputStream inputStream = new JarInputStream(
                getData().getInputStream(ResourceAccess.ONCE));
        try {
            java.util.jar.JarEntry certEntry = inputStream.getNextJarEntry();
            while (certEntry != null) {
                inputStream.closeEntry();
                if (entry.getName().equals(certEntry.getName())) {
                    setCertificates(entry, certEntry);
                }
                setCertificates(getJarEntry(certEntry.getName()), certEntry);
                certEntry = inputStream.getNextJarEntry();
            }
        }
        finally {
            inputStream.close();
        }
    }
    catch (IOException ex) {
        throw new IllegalStateException(ex);
    }
}
项目:spring-boot-concourse    文件:JarFileArchive.java   
private void unpack(JarEntry entry, File file) throws IOException {
    InputStream inputStream = this.jarFile.getInputStream(entry, ResourceAccess.ONCE);
    try {
        OutputStream outputStream = new FileOutputStream(file);
        try {
            byte[] buffer = new byte[BUFFER_SIZE];
            int bytesRead = -1;
            while ((bytesRead = inputStream.read(buffer)) != -1) {
                outputStream.write(buffer, 0, bytesRead);
            }
            outputStream.flush();
        }
        finally {
            outputStream.close();
        }
    }
    finally {
        inputStream.close();
    }
}
项目:spring-boot-concourse    文件:RandomAccessDataFileTests.java   
@Test
public void concurrentReads() throws Exception {
    ExecutorService executorService = Executors.newFixedThreadPool(20);
    List<Future<Boolean>> results = new ArrayList<Future<Boolean>>();
    for (int i = 0; i < 100; i++) {
        results.add(executorService.submit(new Callable<Boolean>() {

            @Override
            public Boolean call() throws Exception {
                InputStream subsectionInputStream = RandomAccessDataFileTests.this.file
                        .getSubsection(0, 256)
                        .getInputStream(ResourceAccess.PER_READ);
                byte[] b = new byte[256];
                subsectionInputStream.read(b);
                return Arrays.equals(b, BYTES);
            }
        }));
    }
    for (Future<Boolean> future : results) {
        assertThat(future.get()).isTrue();
    }
}
项目:contestparser    文件:JarFile.java   
private List<JarEntryData> loadJarEntries(CentralDirectoryEndRecord endRecord)
        throws IOException {
    RandomAccessData centralDirectory = endRecord.getCentralDirectory(this.data);
    int numberOfRecords = endRecord.getNumberOfRecords();
    List<JarEntryData> entries = new ArrayList<JarEntryData>(numberOfRecords);
    InputStream inputStream = centralDirectory.getInputStream(ResourceAccess.ONCE);
    try {
        JarEntryData entry = JarEntryData.fromInputStream(this, inputStream);
        while (entry != null) {
            entries.add(entry);
            processEntry(entry);
            entry = JarEntryData.fromInputStream(this, inputStream);
        }
    }
    finally {
        inputStream.close();
    }
    return entries;
}
项目:contestparser    文件:JarFile.java   
void setupEntryCertificates() {
    // Fallback to JarInputStream to obtain certificates, not fast but hopefully not
    // happening that often.
    try {
        JarInputStream inputStream = new JarInputStream(
                getData().getInputStream(ResourceAccess.ONCE));
        try {
            java.util.jar.JarEntry entry = inputStream.getNextJarEntry();
            while (entry != null) {
                inputStream.closeEntry();
                JarEntry jarEntry = getJarEntry(entry.getName());
                if (jarEntry != null) {
                    jarEntry.setupCertificates(entry);
                }
                entry = inputStream.getNextJarEntry();
            }
        }
        finally {
            inputStream.close();
        }
    }
    catch (IOException ex) {
        throw new IllegalStateException(ex);
    }
}
项目:contestparser    文件:JarFileArchive.java   
private void unpack(JarEntryData data, File file) throws IOException {
    InputStream inputStream = data.getData().getInputStream(ResourceAccess.ONCE);
    try {
        OutputStream outputStream = new FileOutputStream(file);
        try {
            byte[] buffer = new byte[BUFFER_SIZE];
            int bytesRead = -1;
            while ((bytesRead = inputStream.read(buffer)) != -1) {
                outputStream.write(buffer, 0, bytesRead);
            }
            outputStream.flush();
        }
        finally {
            outputStream.close();
        }
    }
    finally {
        inputStream.close();
    }
}
项目:contestparser    文件:RandomAccessDataFileTests.java   
@Test
public void concurrentReads() throws Exception {
    ExecutorService executorService = Executors.newFixedThreadPool(20);
    List<Future<Boolean>> results = new ArrayList<Future<Boolean>>();
    for (int i = 0; i < 100; i++) {
        results.add(executorService.submit(new Callable<Boolean>() {

            @Override
            public Boolean call() throws Exception {
                InputStream subsectionInputStream = RandomAccessDataFileTests.this.file
                        .getSubsection(0, 256)
                        .getInputStream(ResourceAccess.PER_READ);
                byte[] b = new byte[256];
                subsectionInputStream.read(b);
                return Arrays.equals(b, BYTES);
            }
        }));
    }
    for (Future<Boolean> future : results) {
        assertThat(future.get(), equalTo(true));
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:Bytes.java   
public static byte[] get(RandomAccessData data) throws IOException {
    InputStream inputStream = data.getInputStream(ResourceAccess.ONCE);
    try {
        return get(inputStream, data.getSize());
    }
    finally {
        inputStream.close();
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:JarFile.java   
public InputStream getInputStream(ZipEntry ze, ResourceAccess access)
        throws IOException {
    if (ze instanceof JarEntry) {
        return this.entries.getInputStream((JarEntry) ze, access);
    }
    return getInputStream(ze == null ? null : ze.getName(), access);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:JarFileEntries.java   
public InputStream getInputStream(FileHeader entry, ResourceAccess access)
        throws IOException {
    if (entry == null) {
        return null;
    }
    InputStream inputStream = getEntryData(entry).getInputStream(access);
    if (entry.getMethod() == ZipEntry.DEFLATED) {
        inputStream = new ZipInflaterInputStream(inputStream, (int) entry.getSize());
    }
    return inputStream;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:RandomAccessDataFileTests.java   
@Before
public void setup() throws Exception {
    this.tempFile = this.temporaryFolder.newFile();
    FileOutputStream outputStream = new FileOutputStream(this.tempFile);
    outputStream.write(BYTES);
    outputStream.close();
    this.file = new RandomAccessDataFile(this.tempFile);
    this.inputStream = this.file.getInputStream(ResourceAccess.PER_READ);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:RandomAccessDataFileTests.java   
@Test
public void inputStreamReadPastSubsection() throws Exception {
    RandomAccessData subsection = this.file.getSubsection(1, 2);
    InputStream inputStream = subsection.getInputStream(ResourceAccess.PER_READ);
    assertThat(inputStream.read()).isEqualTo(1);
    assertThat(inputStream.read()).isEqualTo(2);
    assertThat(inputStream.read()).isEqualTo(-1);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:RandomAccessDataFileTests.java   
@Test
public void inputStreamReadBytesPastSubsection() throws Exception {
    RandomAccessData subsection = this.file.getSubsection(1, 2);
    InputStream inputStream = subsection.getInputStream(ResourceAccess.PER_READ);
    byte[] b = new byte[3];
    int amountRead = inputStream.read(b);
    assertThat(b).isEqualTo(new byte[] { 1, 2, 0 });
    assertThat(amountRead).isEqualTo(2);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:RandomAccessDataFileTests.java   
@Test
public void inputStreamSkipPastSubsection() throws Exception {
    RandomAccessData subsection = this.file.getSubsection(1, 2);
    InputStream inputStream = subsection.getInputStream(ResourceAccess.PER_READ);
    assertThat(inputStream.skip(3)).isEqualTo(2L);
    assertThat(inputStream.read()).isEqualTo(-1);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:RandomAccessDataFileTests.java   
@Test
public void close() throws Exception {
    this.file.getInputStream(ResourceAccess.PER_READ).read();
    this.file.close();
    Field filePoolField = RandomAccessDataFile.class.getDeclaredField("filePool");
    filePoolField.setAccessible(true);
    Object filePool = filePoolField.get(this.file);
    Field filesField = filePool.getClass().getDeclaredField("files");
    filesField.setAccessible(true);
    Queue<?> queue = (Queue<?>) filesField.get(filePool);
    assertThat(queue.size()).isEqualTo(0);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ByteArrayRandomAccessDataTests.java   
@Test
public void testGetInputStream() throws Exception {
    byte[] bytes = new byte[] { 0, 1, 2, 3, 4, 5 };
    RandomAccessData data = new ByteArrayRandomAccessData(bytes);
    InputStream inputStream = data.getInputStream(ResourceAccess.PER_READ);
    assertThat(FileCopyUtils.copyToByteArray(inputStream)).isEqualTo(bytes);
    assertThat(data.getSize()).isEqualTo(bytes.length);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ByteArrayRandomAccessDataTests.java   
@Test
public void testGetSubsection() throws Exception {
    byte[] bytes = new byte[] { 0, 1, 2, 3, 4, 5 };
    RandomAccessData data = new ByteArrayRandomAccessData(bytes);
    data = data.getSubsection(1, 4).getSubsection(1, 2);
    InputStream inputStream = data.getInputStream(ResourceAccess.PER_READ);
    assertThat(FileCopyUtils.copyToByteArray(inputStream))
            .isEqualTo(new byte[] { 2, 3 });
    assertThat(data.getSize()).isEqualTo(2L);
}
项目:spring-boot-concourse    文件:Bytes.java   
public static byte[] get(RandomAccessData data) throws IOException {
    InputStream inputStream = data.getInputStream(ResourceAccess.ONCE);
    try {
        return get(inputStream, data.getSize());
    }
    finally {
        inputStream.close();
    }
}
项目:spring-boot-concourse    文件:JarFile.java   
public InputStream getInputStream(ZipEntry ze, ResourceAccess access)
        throws IOException {
    if (ze instanceof JarEntry) {
        return this.entries.getInputStream((JarEntry) ze, access);
    }
    return getInputStream(ze == null ? null : ze.getName(), access);
}
项目:spring-boot-concourse    文件:JarFileEntries.java   
public InputStream getInputStream(FileHeader entry, ResourceAccess access)
        throws IOException {
    if (entry == null) {
        return null;
    }
    InputStream inputStream = getEntryData(entry).getInputStream(access);
    if (entry.getMethod() == ZipEntry.DEFLATED) {
        inputStream = new ZipInflaterInputStream(inputStream, (int) entry.getSize());
    }
    return inputStream;
}
项目:spring-boot-concourse    文件:RandomAccessDataFileTests.java   
@Before
public void setup() throws Exception {
    this.tempFile = this.temporaryFolder.newFile();
    FileOutputStream outputStream = new FileOutputStream(this.tempFile);
    outputStream.write(BYTES);
    outputStream.close();
    this.file = new RandomAccessDataFile(this.tempFile);
    this.inputStream = this.file.getInputStream(ResourceAccess.PER_READ);
}
项目:spring-boot-concourse    文件:RandomAccessDataFileTests.java   
@Test
public void inputStreamReadPastSubsection() throws Exception {
    RandomAccessData subsection = this.file.getSubsection(1, 2);
    InputStream inputStream = subsection.getInputStream(ResourceAccess.PER_READ);
    assertThat(inputStream.read()).isEqualTo(1);
    assertThat(inputStream.read()).isEqualTo(2);
    assertThat(inputStream.read()).isEqualTo(-1);
}
项目:spring-boot-concourse    文件:RandomAccessDataFileTests.java   
@Test
public void inputStreamReadBytesPastSubsection() throws Exception {
    RandomAccessData subsection = this.file.getSubsection(1, 2);
    InputStream inputStream = subsection.getInputStream(ResourceAccess.PER_READ);
    byte[] b = new byte[3];
    int amountRead = inputStream.read(b);
    assertThat(b).isEqualTo(new byte[] { 1, 2, 0 });
    assertThat(amountRead).isEqualTo(2);
}
项目:spring-boot-concourse    文件:RandomAccessDataFileTests.java   
@Test
public void inputStreamSkipPastSubsection() throws Exception {
    RandomAccessData subsection = this.file.getSubsection(1, 2);
    InputStream inputStream = subsection.getInputStream(ResourceAccess.PER_READ);
    assertThat(inputStream.skip(3)).isEqualTo(2L);
    assertThat(inputStream.read()).isEqualTo(-1);
}
项目:spring-boot-concourse    文件:RandomAccessDataFileTests.java   
@Test
public void close() throws Exception {
    this.file.getInputStream(ResourceAccess.PER_READ).read();
    this.file.close();
    Field filePoolField = RandomAccessDataFile.class.getDeclaredField("filePool");
    filePoolField.setAccessible(true);
    Object filePool = filePoolField.get(this.file);
    Field filesField = filePool.getClass().getDeclaredField("files");
    filesField.setAccessible(true);
    Queue<?> queue = (Queue<?>) filesField.get(filePool);
    assertThat(queue.size()).isEqualTo(0);
}
项目:spring-boot-concourse    文件:ByteArrayRandomAccessDataTests.java   
@Test
public void testGetInputStream() throws Exception {
    byte[] bytes = new byte[] { 0, 1, 2, 3, 4, 5 };
    RandomAccessData data = new ByteArrayRandomAccessData(bytes);
    InputStream inputStream = data.getInputStream(ResourceAccess.PER_READ);
    assertThat(FileCopyUtils.copyToByteArray(inputStream)).isEqualTo(bytes);
    assertThat(data.getSize()).isEqualTo(bytes.length);
}
项目:spring-boot-concourse    文件:ByteArrayRandomAccessDataTests.java   
@Test
public void testGetSubsection() throws Exception {
    byte[] bytes = new byte[] { 0, 1, 2, 3, 4, 5 };
    RandomAccessData data = new ByteArrayRandomAccessData(bytes);
    data = data.getSubsection(1, 4).getSubsection(1, 2);
    InputStream inputStream = data.getInputStream(ResourceAccess.PER_READ);
    assertThat(FileCopyUtils.copyToByteArray(inputStream))
            .isEqualTo(new byte[] { 2, 3 });
    assertThat(data.getSize()).isEqualTo(2L);
}
项目:contestparser    文件:JarEntryData.java   
InputStream getInputStream() throws IOException {
    InputStream inputStream = getData().getInputStream(ResourceAccess.PER_READ);
    if (getMethod() == ZipEntry.DEFLATED) {
        inputStream = new ZipInflaterInputStream(inputStream, getSize());
    }
    return inputStream;
}
项目:contestparser    文件:Bytes.java   
public static byte[] get(RandomAccessData data) throws IOException {
    InputStream inputStream = data.getInputStream(ResourceAccess.ONCE);
    try {
        return get(inputStream, data.getSize());
    }
    finally {
        inputStream.close();
    }
}
项目:contestparser    文件:RandomAccessDataFileTests.java   
@Before
public void setup() throws Exception {
    this.tempFile = this.temporaryFolder.newFile();
    FileOutputStream outputStream = new FileOutputStream(this.tempFile);
    outputStream.write(BYTES);
    outputStream.close();
    this.file = new RandomAccessDataFile(this.tempFile);
    this.inputStream = this.file.getInputStream(ResourceAccess.PER_READ);
}
项目:contestparser    文件:RandomAccessDataFileTests.java   
@Test
public void inputStreamReadPastSubsection() throws Exception {
    RandomAccessData subsection = this.file.getSubsection(1, 2);
    InputStream inputStream = subsection.getInputStream(ResourceAccess.PER_READ);
    assertThat(inputStream.read(), equalTo(1));
    assertThat(inputStream.read(), equalTo(2));
    assertThat(inputStream.read(), equalTo(-1));
}
项目:contestparser    文件:RandomAccessDataFileTests.java   
@Test
public void inputStreamReadBytesPastSubsection() throws Exception {
    RandomAccessData subsection = this.file.getSubsection(1, 2);
    InputStream inputStream = subsection.getInputStream(ResourceAccess.PER_READ);
    byte[] b = new byte[3];
    int amountRead = inputStream.read(b);
    assertThat(b, equalTo(new byte[] { 1, 2, 0 }));
    assertThat(amountRead, equalTo(2));
}
项目:contestparser    文件:RandomAccessDataFileTests.java   
@Test
public void inputStreamSkipPastSubsection() throws Exception {
    RandomAccessData subsection = this.file.getSubsection(1, 2);
    InputStream inputStream = subsection.getInputStream(ResourceAccess.PER_READ);
    assertThat(inputStream.skip(3), equalTo(2L));
    assertThat(inputStream.read(), equalTo(-1));
}
项目:contestparser    文件:RandomAccessDataFileTests.java   
@Test
public void close() throws Exception {
    this.file.getInputStream(ResourceAccess.PER_READ).read();
    this.file.close();
    Field filePoolField = RandomAccessDataFile.class.getDeclaredField("filePool");
    filePoolField.setAccessible(true);
    Object filePool = filePoolField.get(this.file);
    Field filesField = filePool.getClass().getDeclaredField("files");
    filesField.setAccessible(true);
    Queue<?> queue = (Queue<?>) filesField.get(filePool);
    assertThat(queue.size(), equalTo(0));
}
项目:contestparser    文件:ByteArrayRandomAccessDataTests.java   
@Test
public void testGetInputStream() throws Exception {
    byte[] bytes = new byte[] { 0, 1, 2, 3, 4, 5 };
    RandomAccessData data = new ByteArrayRandomAccessData(bytes);
    assertThat(FileCopyUtils.copyToByteArray(
            data.getInputStream(ResourceAccess.PER_READ)), equalTo(bytes));
    assertThat(data.getSize(), equalTo((long) bytes.length));
}