Java Code Examples for java.io.IOError

The following examples show how to use java.io.IOError. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: TencentKona-8   Author: Tencent   File: Command.java    License: GNU General Public License v2.0 6 votes vote down vote up
final protected Path getJFRInputFile(Deque<String> options) throws UserSyntaxException, UserDataException {
    if (options.isEmpty()) {
        throw new UserSyntaxException("missing file");
    }
    String file = options.removeLast();
    if (file.startsWith("--")) {
        throw new UserSyntaxException("missing file");
    }
    try {
        Path path = Paths.get(file).toAbsolutePath();
        ensureAccess(path);
        ensureJFRFile(path);
        return path;
    } catch (IOError ioe) {
        throw new UserDataException("i/o error reading file '" + file + "', " + ioe.getMessage());
    } catch (InvalidPathException ipe) {
        throw new UserDataException("invalid path '" + file + "'");
    }
}
 
Example #2
Source Project: blueflood   Author: rackerlabs   File: RollupSerializationHelper.java    License: Apache License 2.0 6 votes vote down vote up
public static ObjectNode rollupToJson(Rollup rollup) {
    if (rollup instanceof BluefloodCounterRollup)
        return handleCounterRollup((BluefloodCounterRollup)rollup);
    else if (rollup instanceof BluefloodTimerRollup)
        return handleTimerRollup((BluefloodTimerRollup)rollup);
    else if (rollup instanceof BluefloodSetRollup)
        return handleSetRollup((BluefloodSetRollup)rollup);
    else if (rollup instanceof BluefloodGaugeRollup)
        return handleGaugeRollup((BluefloodGaugeRollup)rollup);
    else if (rollup instanceof BasicRollup)
        return handleBasicRollup((BasicRollup)rollup, JsonNodeFactory.instance.objectNode());
    else {
        log.error("Error encountered while serializing the rollup "+rollup);
        throw new IOError(new IOException("Cannot serialize the Rollup : "+rollup));
    }
}
 
Example #3
Source Project: graphdb-benchmarks   Author: socialsensor   File: TitanGraphDatabase.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void shutdown()
{
    if (titanGraph == null)
    {
        return;
    }
    try
    {
        titanGraph.shutdown();
    }
    catch (IOError e)
    {
        // TODO Fix issue in shutting down titan-cassandra-embedded
        System.err.println("Failed to shutdown titan graph: " + e.getMessage());
    }

    titanGraph = null;
}
 
Example #4
Source Project: quarkus   Author: quarkusio   File: ApplicationPropertiesConfigSource.java    License: Apache License 2.0 6 votes vote down vote up
private static Map<String, String> readProperties(final InputStream is) {
    if (is == null) {
        return Collections.emptyMap();
    }
    try (Closeable ignored = is) {
        try (InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8)) {
            try (BufferedReader br = new BufferedReader(isr)) {
                final Properties properties = new Properties();
                properties.load(br);
                return (Map<String, String>) (Map) properties;
            }
        }
    } catch (IOException e) {
        throw new IOError(e);
    }
}
 
Example #5
Source Project: stratio-cassandra   Author: Stratio   File: StressProfile.java    License: Apache License 2.0 6 votes vote down vote up
public static StressProfile load(URI file) throws IOError
{
    try
    {
        Constructor constructor = new Constructor(StressYaml.class);

        Yaml yaml = new Yaml(constructor);

        InputStream yamlStream = file.toURL().openStream();

        if (yamlStream.available() == 0)
            throw new IOException("Unable to load yaml file from: "+file);

        StressYaml profileYaml = yaml.loadAs(yamlStream, StressYaml.class);

        StressProfile profile = new StressProfile();
        profile.init(profileYaml);

        return profile;
    }
    catch (YAMLException | IOException | RequestValidationException e)
    {
        throw new IOError(e);
    }
}
 
Example #6
Source Project: quarkus   Author: quarkusio   File: ExceptionUtilTest.java    License: Apache License 2.0 6 votes vote down vote up
private Throwable generateException() {
    try {
        try {
            Integer.parseInt("23.23232");
        } catch (NumberFormatException nfe) {
            throw new IllegalArgumentException("Incorrect param", nfe);
        }
    } catch (IllegalArgumentException iae) {
        try {
            throw new IOException("Request processing failed", iae);
        } catch (IOException e) {
            try {
                throw new IOError(e);
            } catch (IOError ie) {
                return new RuntimeException("Unexpected exception", ie);
            }
        }
    }
    throw new RuntimeException("Should not reach here");
}
 
Example #7
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: Command.java    License: GNU General Public License v2.0 6 votes vote down vote up
final protected Path getJFRInputFile(Deque<String> options) throws UserSyntaxException, UserDataException {
    if (options.isEmpty()) {
        throw new UserSyntaxException("missing file");
    }
    String file = options.removeLast();
    if (file.startsWith("--")) {
        throw new UserSyntaxException("missing file");
    }
    try {
        Path path = Paths.get(file).toAbsolutePath();
        ensureAccess(path);
        ensureJFRFile(path);
        return path;
    } catch (IOError ioe) {
        throw new UserDataException("i/o error reading file '" + file + "', " + ioe.getMessage());
    } catch (InvalidPathException ipe) {
        throw new UserDataException("invalid path '" + file + "'");
    }
}
 
Example #8
Source Project: Bytecoder   Author: mirkosertic   File: JrtPath.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public final URI toUri() {
    try {
        String p = toAbsolutePath().path;
        if (!p.startsWith("/modules") || p.contains("..")) {
            throw new IOError(new RuntimeException(p + " cannot be represented as URI"));
        }

        p = p.substring("/modules".length());
        if (p.isEmpty()) {
            p = "/";
        }
        return new URI("jrt", p, null);
    } catch (URISyntaxException ex) {
        throw new AssertionError(ex);
    }
}
 
Example #9
Source Project: bazel   Author: bazelbuild   File: DirectoryInputFileProvider.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Iterator<String> iterator() {
  final List<String> entries = new ArrayList<>();
  try (Stream<Path> paths = Files.walk(root)) {
    paths.forEach(
        new Consumer<Path>() {
          @Override
          public void accept(Path t) {
            if (Files.isRegularFile(t)) {
              // Internally, we use '/' as a common package separator in filename to abstract
              // that filename can comes from a zip or a directory.
              entries.add(root.relativize(t).toString().replace(File.separatorChar, '/'));
            }
          }
        });
  } catch (IOException e) {
    throw new IOError(e);
  }
  return entries.iterator();
}
 
Example #10
Source Project: bazel   Author: bazelbuild   File: DesugarMethodAttribute.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected Attribute read(
    ClassReader classReader,
    int offset,
    int length,
    char[] charBuffer,
    int codeAttributeOffset,
    Label[] labels) {
  byte[] classAttrBytes = new byte[length];
  for (int i = 0; i < length; i++) {
    classAttrBytes[i] = (byte) classReader.readByte(i + offset);
  }
  try {
    return new DesugarMethodAttribute(
        DesugarMethodInfo.parseFrom(classAttrBytes, ExtensionRegistryLite.getEmptyRegistry()));
  } catch (InvalidProtocolBufferException e) {
    throw new IOError(e);
  }
}
 
Example #11
Source Project: keycloak   Author: keycloak   File: KeycloakPropertiesConfigSource.java    License: Apache License 2.0 6 votes vote down vote up
private static Map<String, String> readProperties(final InputStream is) {
    if (is == null) {
        return Collections.emptyMap();
    }
    try (Closeable ignored = is) {
        try (InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8)) {
            try (BufferedReader br = new BufferedReader(isr)) {
                final Properties properties = new Properties();
                properties.load(br);
                return transform((Map<String, String>) (Map) properties);
            }
        }
    } catch (IOException e) {
        throw new IOError(e);
    }
}
 
Example #12
Source Project: bazel   Author: bazelbuild   File: InputFileProvider.java    License: Apache License 2.0 6 votes vote down vote up
default ImmutableList<FileContentProvider<? extends InputStream>> toInputFileStreams() {
  ImmutableList.Builder<FileContentProvider<? extends InputStream>> inputClassFileContents =
      ImmutableList.builder();
  for (String inputFileName : this) {
    inputClassFileContents.add(
        new FileContentProvider<>(
            inputFileName,
            () -> {
              try {
                return getInputStream(inputFileName);
              } catch (IOException e) {
                throw new IOError(e);
              }
            }));
  }
  return inputClassFileContents.build();
}
 
Example #13
Source Project: scava   Author: crossminer   File: Volume.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void close() {
    growLock.lock();
    try{
        fileChannel.close();
        raf.close();
        if(!readOnly)
            sync();
        for(ByteBuffer b:buffers){
            if(b!=null && (b instanceof MappedByteBuffer)){
                unmap((MappedByteBuffer) b);
            }
        }
        buffers = null;
    } catch (IOException e) {
        throw new IOError(e);
    }finally{
        growLock.unlock();
    }

}
 
Example #14
Source Project: scava   Author: crossminer   File: Volume.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected ByteBuffer makeNewBuffer(long offset) {
    try {
        long newBufSize =  offset% BUF_SIZE;
        newBufSize = newBufSize + newBufSize%BUF_SIZE_INC; //round to BUF_SIZE_INC
        return fileChannel.map(
                mapMode,
                offset - offset% BUF_SIZE, newBufSize );
    } catch (IOException e) {
        if(e.getCause()!=null && e.getCause() instanceof OutOfMemoryError){
            throw new RuntimeException("File could not be mapped to memory, common problem on 32bit JVM. Use `DBMaker.newRandomAccessFileDB()` as workaround",e);
        }

        throw new IOError(e);
    }
}
 
Example #15
Source Project: camel-spring-boot   Author: apache   File: AbstractSpringBootGenerator.java    License: Apache License 2.0 5 votes vote down vote up
protected static String loadJson(JarFile jar, JarEntry je) {
    try (InputStream is = jar.getInputStream(je)) {
        return PackageHelper.loadText(is);
    } catch (IOException e) {
        throw new IOError(e);
    }
}
 
Example #16
Source Project: android-auto-call-recorder   Author: AnthonyNahas   File: FileHelper.java    License: MIT License 5 votes vote down vote up
private void getAllChildDirectories(File parentDir) {

        try {
            File[] allFiles = parentDir.listFiles();
            logFiles(allFiles);
        } catch (IOError e) {
            Log.e(TAG, "error " + e);
        }
    }
 
Example #17
Source Project: qpid-broker-j   Author: apache   File: BrokerLoggerStatusListenerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testAddStatusEventForIOErrorWithFailOnLoggerIOErrorDisabled()
{
    Status event = createEvent(new IOError(new IOException("Mocked: No disk space left")), Status.ERROR);
    when(_fileLogger.getContextValue(Boolean.class, BrokerFileLogger.BROKER_FAIL_ON_LOGGER_IO_ERROR)).thenReturn(false);
    _statusListener.addStatusEvent(event);

    verify(_systemConfig, never()).closeAsync();
}
 
Example #18
Source Project: warnings-ng-plugin   Author: jenkinsci   File: TestDashboard.java    License: MIT License 5 votes vote down vote up
public File asFile() {
    try {
        return new File(url.toURI());
    } catch (URISyntaxException e) {
        throw new IOError(e);
    }
}
 
Example #19
Source Project: bazel   Author: bazelbuild   File: ResourceBasedClassFiles.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public FileContentProvider<InputStream> getContent(ClassName className) {
  String inArchiveBinaryPathName = className.classFilePathName();
  return new FileContentProvider<>(
      inArchiveBinaryPathName,
      () -> {
        try {
          return Resources.getResource(inArchiveBinaryPathName).openStream();
        } catch (IOException e) {
          throw new IOError(e);
        }
      });
}
 
Example #20
Source Project: java-n-IDE-for-Android   Author: shenghuntianlang   File: Trees.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns the source text for the node.
 */
static String getSourceForNode(Tree node, TreePath path) {
    CharSequence source;
    try {
        source = path.getCompilationUnit().getSourceFile().getCharContent(false);
    } catch (IOException e) {
        throw new IOError(e);
    }
    return source.subSequence(getStartPosition(node), getEndPosition(node, path)).toString();
}
 
Example #21
Source Project: quarkus   Author: quarkusio   File: JaxbProcessor.java    License: Apache License 2.0 5 votes vote down vote up
public static Stream<Path> safeWalk(Path p) {
    try {
        return Files.walk(p);
    } catch (IOException e) {
        throw new IOError(e);
    }
}
 
Example #22
Source Project: powsybl-core   Author: powsybl   File: JsonLoadFlowParametersTest.java    License: Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void updateExtension() throws IOError {
    LoadFlowParameters parameters = new LoadFlowParameters();
    DummyExtension extension = new DummyExtension();
    extension.setParameterDouble(2.5);
    extension.setParameterBoolean(false);
    extension.setParameterString("Hello World !");
    DummyExtension oldExtension = new DummyExtension(extension);
    parameters.addExtension(DummyExtension.class, extension);
    JsonLoadFlowParameters.update(parameters, getClass().getResourceAsStream("/LoadFlowParametersUpdate.json"));
    extension = parameters.getExtension(DummyExtension.class);
    assertEquals(oldExtension.isParameterBoolean(), extension.isParameterBoolean());
    assertNotEquals(oldExtension.getParameterDouble(), extension.getParameterDouble());
    assertNotEquals(oldExtension.getParameterString(), extension.getParameterString());
}
 
Example #23
Source Project: centraldogma   Author: line   File: TestUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static <T> void assertJsonConversion(T value, Class<T> valueType, String json) {
    assertThatJson(json).isEqualTo(value);
    try {
        assertThat(Jackson.readValue(json, valueType)).isEqualTo(value);
    } catch (IOException e) {
        throw new IOError(e);
    }
}
 
Example #24
Source Project: scava   Author: crossminer   File: VolumeTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void read_beyond_end_raf_byte(){
    try{
        Volume v = new Volume.RandomAccessFileVol(Utils.tempDbFile(), false);
        v.getByte(1000000);
        fail();
    }catch(IOError e){
        assertTrue(e.getCause() instanceof  EOFException);
    }
}
 
Example #25
Source Project: FastBootWeixin   Author: FastBootWeixin   File: StoreWAL.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public <A> A get(long recid, Serializer<A> serializer) {
    assert(recid>0);
    final long ioRecid = IO_USER_START + recid*8;
    final Lock lock  = locks[Store.lockPos(ioRecid)].readLock();
    lock.lock();
    try{
        return get2(ioRecid, serializer);
    }catch(IOException e){
        throw new IOError(e);
    }finally{
        lock.unlock();
    }
}
 
Example #26
Source Project: javaide   Author: tranleduy2000   File: TestJavacParser.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void test4() {
    Context context = new Context();
    DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
    context.put(DiagnosticListener.class, diagnostics);
    Options.instance(context).put("allowStringFolding", "false");
    JCTree.JCCompilationUnit unit;
    JavacFileManager fileManager = new JavacFileManager(context, true, UTF_8);
    try {
        fileManager.setLocation(StandardLocation.PLATFORM_CLASS_PATH, ImmutableList.<File>of());
    } catch (IOException e) {
        // impossible
        throw new IOError(e);
    }
    SimpleJavaFileObject source =
            new SimpleJavaFileObject(URI.create("source"), JavaFileObject.Kind.SOURCE) {
                @Override
                public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
                    return src;
                }
            };
    Log.instance(context).useSource(source);
    ParserFactory parserFactory = ParserFactory.instance(context);
    Parser parser =
            parserFactory.newParser(
                    src,
        /*keepDocComments=*/ true,
        /*keepEndPos=*/ true,
        /*keepLineMap=*/ true);
    unit = parser.parseCompilationUnit();
    unit.sourcefile = source;
}
 
Example #27
Source Project: google-java-format   Author: google   File: RemoveUnusedImports.java    License: Apache License 2.0 5 votes vote down vote up
private static JCCompilationUnit parse(Context context, String javaInput)
    throws FormatterException {
  DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
  context.put(DiagnosticListener.class, diagnostics);
  Options.instance(context).put("--enable-preview", "true");
  Options.instance(context).put("allowStringFolding", "false");
  JCCompilationUnit unit;
  JavacFileManager fileManager = new JavacFileManager(context, true, UTF_8);
  try {
    fileManager.setLocation(StandardLocation.PLATFORM_CLASS_PATH, ImmutableList.of());
  } catch (IOException e) {
    // impossible
    throw new IOError(e);
  }
  SimpleJavaFileObject source =
      new SimpleJavaFileObject(URI.create("source"), JavaFileObject.Kind.SOURCE) {
        @Override
        public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
          return javaInput;
        }
      };
  Log.instance(context).useSource(source);
  ParserFactory parserFactory = ParserFactory.instance(context);
  JavacParser parser =
      parserFactory.newParser(
          javaInput, /*keepDocComments=*/ true, /*keepEndPos=*/ true, /*keepLineMap=*/ true);
  unit = parser.parseCompilationUnit();
  unit.sourcefile = source;
  Iterable<Diagnostic<? extends JavaFileObject>> errorDiagnostics =
      Iterables.filter(diagnostics.getDiagnostics(), Formatter::errorDiagnostic);
  if (!Iterables.isEmpty(errorDiagnostics)) {
    // error handling is done during formatting
    throw FormatterException.fromJavacDiagnostics(errorDiagnostics);
  }
  return unit;
}
 
Example #28
Source Project: javaide   Author: tranleduy2000   File: Trees.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the source text for the node.
 */
static String getSourceForNode(Tree node, TreePath path) {
    CharSequence source;
    try {
        source = path.getCompilationUnit().getSourceFile().getCharContent(false);
    } catch (IOException e) {
        throw new IOError(e);
    }
    return source.subSequence(getStartPosition(node), getEndPosition(node, path)).toString();
}
 
Example #29
Source Project: Bytecoder   Author: mirkosertic   File: ModuleReferences.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Optional<URI> find(String name) throws IOException {
    ensureOpen();
    Path path = Resources.toFilePath(dir, name);
    if (path != null) {
        try {
            return Optional.of(path.toUri());
        } catch (IOError e) {
            throw (IOException) e.getCause();
        }
    } else {
        return Optional.empty();
    }
}
 
Example #30
Source Project: wildfly-core   Author: wildfly   File: JavaConsole.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public String readLine(String fmt, Object... args) throws IOError {
    if (hasConsole()) {
        return theConsole.readLine(fmt, args);
    } else {
        throw ROOT_LOGGER.noConsoleAvailable();
    }
}