List of usage examples for java.io FileNotFoundException FileNotFoundException
public FileNotFoundException()
FileNotFoundException
with null
as its error detail message. From source file:Main.java
/** * @return/*w w w. j a va 2s .c o m*/ * @throws IOException */ public static String getDataFromFile(String dataFileName) throws IOException { FileInputStream inputStream = null; try { inputStream = new FileInputStream(dataFileName); } catch (IOException e) { e.printStackTrace(); } String _jsonGspTxt = null; if (inputStream != null) { BufferedReader myReader = new BufferedReader(new InputStreamReader(inputStream)); String _row = ""; StringBuffer _buffer = new StringBuffer(); while ((_row = myReader.readLine()) != null) { _buffer.append(_row); } _jsonGspTxt = _buffer.toString(); // _fIn.close(); myReader.close(); } else { throw new FileNotFoundException(); } return _jsonGspTxt; }
From source file:msuresh.raftdistdb.RaftClient.java
public static void SetValue(String name, String key, String value) throws FileNotFoundException { if (key == null || key.isEmpty()) { return;/*from w w w . j av a 2 s . c o m*/ } File configFile = new File(Constants.STATE_LOCATION + name + ".info"); if (!configFile.exists() || configFile.isDirectory()) { FileNotFoundException ex = new FileNotFoundException(); throw ex; } try { System.out.println("Adding key .. hold on.."); String content = new Scanner(configFile).useDelimiter("\\Z").next(); JSONObject config = (JSONObject) (new JSONParser()).parse(content); Long numPart = (Long) config.get("countPartitions"); Integer shardId = key.hashCode() % numPart.intValue(); JSONArray memberJson = (JSONArray) config.get(shardId.toString()); List<Address> members = new ArrayList<>(); for (int i = 0; i < memberJson.size(); i++) { JSONObject obj = (JSONObject) memberJson.get(i); Long port = (Long) obj.get("port"); String address = (String) obj.get("address"); members.add(new Address(address, port.intValue())); } CopycatClient client = CopycatClient.builder(members).withTransport(new NettyTransport()).build(); client.open().join(); client.submit(new PutCommand(key, value)).get(); client.close().join(); while (client.isOpen()) { Thread.sleep(1000); } System.out.println("key " + key + " with value : " + value + " has been added to the cluster"); } catch (Exception ex) { System.out.println(ex.toString()); } }
From source file:com.haulmont.cuba.core.sys.logging.LogArchiver.java
public static void writeArchivedLogTailToStream(File logFile, OutputStream outputStream) throws IOException { if (!logFile.exists()) { throw new FileNotFoundException(); }//from www . j a v a 2 s . c o m ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(outputStream); zipOutputStream.setMethod(ZipArchiveOutputStream.DEFLATED); zipOutputStream.setEncoding(ZIP_ENCODING); byte[] content = getTailBytes(logFile); ArchiveEntry archiveEntry = newTailArchive(logFile.getName(), content); zipOutputStream.putArchiveEntry(archiveEntry); zipOutputStream.write(content); zipOutputStream.closeArchiveEntry(); zipOutputStream.close(); }
From source file:Api.RequestValidator.java
public void validate() throws NotSuportedFileFormatException, FileNotFoundException { if (!checkFileExists()) throw new FileNotFoundException(); if (!checkFileFormat()) throw new NotSuportedFileFormatException(FilenameUtils.getExtension(filePath)); }
From source file:com.gmail.frogocomics.schematic.BiomeWorldV2Object.java
public static BiomeWorldV2Object load(File file) throws IOException { BufferedReader settingsReader; if (!file.exists()) { throw new FileNotFoundException(); }// ww w . j a v a 2s . c o m settingsReader = new BufferedReader(new FileReader(file)); int lineNumber = 0; String thisLine; ArrayList<BiomeWorldObjectBlock> bo2Blocks = new ArrayList<>(); while ((thisLine = settingsReader.readLine()) != null) { lineNumber++; if (Pattern.compile("[0-9]").matcher(thisLine.substring(0, 1)).matches() || thisLine.substring(0, 1).equalsIgnoreCase("-")) { //Example: -1,-1,5:18.4 // x,z,y:id.data String[] location = thisLine.split(":")[0].split(","); String[] block = thisLine.split(":")[1].split("\\."); bo2Blocks.add(new BiomeWorldObjectBlock(Integer.parseInt(location[0]), Integer.parseInt(location[2]), Integer.parseInt(location[1]), Short.parseShort(block[0]), Byte.parseByte(block[1]))); } } ArrayList<Integer> maxXMap = new ArrayList<>(); ArrayList<Integer> maxYMap = new ArrayList<>(); ArrayList<Integer> maxZMap = new ArrayList<>(); for (BiomeWorldObjectBlock bo2 : bo2Blocks) { maxXMap.add(bo2.getX()); maxYMap.add(bo2.getY()); maxZMap.add(bo2.getZ()); } int maxX = Collections.max(maxXMap); int maxY = Collections.max(maxYMap); int maxZ = Collections.max(maxZMap); int minX = Collections.min(maxXMap); int minY = Collections.min(maxYMap); int minZ = Collections.min(maxZMap); int differenceX = maxX - minX + 1; int differenceY = maxY - minY + 1; int differenceZ = maxZ - minZ + 1; HashMap<Integer, Set<BiomeWorldObjectBlock>> blocks = new HashMap<>(); for (int i = 0; i < differenceY + 1; i++) { blocks.put(i, new HashSet<>()); } for (BiomeWorldObjectBlock bo2 : bo2Blocks) { Set<BiomeWorldObjectBlock> a = blocks.get(bo2.getY() - minY); a.add(bo2); blocks.replace(bo2.getY(), a); } //System.out.println(differenceX + " " + differenceZ); SliceStack schematic = new SliceStack(differenceY, differenceX, differenceZ); for (Map.Entry<Integer, Set<BiomeWorldObjectBlock>> next : blocks.entrySet()) { Slice slice = new Slice(differenceX, differenceZ); for (BiomeWorldObjectBlock block : next.getValue()) { //System.out.println("Added block at " + String.valueOf(block.getX() - minX) + "," + String.valueOf(block.getZ() - minZ)); slice.setBlock(block.getBlock(), block.getX() - minX, block.getZ() - minZ); } schematic.addSlice(slice); } //System.out.println(schematic.toString()); return new BiomeWorldV2Object(schematic, FilenameUtils.getBaseName(file.getAbsolutePath())); }
From source file:HttpUtils.java
public static void testUrl(String url) throws ClientProtocolException, IOException { HttpHead head = new HttpHead(url); HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = httpclient.execute(head); StatusLine status = response.getStatusLine(); if (status.getStatusCode() == 404) { throw new FileNotFoundException(); }//w ww . j ava 2 s .co m if (status.getStatusCode() != 200) { throw new RuntimeException( "Could not get URL: " + status.getStatusCode() + ": " + status.getReasonPhrase()); } }
From source file:fm.moe.android.util.JSONFileHelper.java
public static JSONObject read(final String path) throws IOException, JSONException { if (path == null) throw new FileNotFoundException(); final File file = new File(path); if (!file.isFile()) throw new FileNotFoundException(); return new JSONObject(readFile(file)); }
From source file:com.haulmont.cuba.core.sys.logging.LogArchiver.java
public static void writeArchivedLogToStream(File logFile, OutputStream outputStream) throws IOException { if (!logFile.exists()) { throw new FileNotFoundException(); }/* ww w .j a v a2 s .c o m*/ File tempFile = File.createTempFile(FilenameUtils.getBaseName(logFile.getName()) + "_log_", ".zip"); ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(tempFile); zipOutputStream.setMethod(ZipArchiveOutputStream.DEFLATED); zipOutputStream.setEncoding(ZIP_ENCODING); ArchiveEntry archiveEntry = newArchive(logFile); zipOutputStream.putArchiveEntry(archiveEntry); FileInputStream logFileInput = new FileInputStream(logFile); IOUtils.copyLarge(logFileInput, zipOutputStream); logFileInput.close(); zipOutputStream.closeArchiveEntry(); zipOutputStream.close(); FileInputStream tempFileInput = new FileInputStream(tempFile); IOUtils.copyLarge(tempFileInput, outputStream); tempFileInput.close(); FileUtils.deleteQuietly(tempFile); }
From source file:com.thoughtworks.go.plugin.infra.commons.PluginUploadResponseTest.java
@Test public void shouldCreateAResponseWithErrors() { Map<Integer, String> errors = new HashMap<>(); int errorCode = HttpStatus.SC_INTERNAL_SERVER_ERROR; String errorMessage = new FileNotFoundException().getMessage(); errors.put(errorCode, errorMessage); PluginUploadResponse response = PluginUploadResponse.create(false, null, errors); assertThat(response.success(), is("")); assertThat(response.errors().get(errorCode), is(errorMessage)); }
From source file:it.polito.tellmefirst.enhancer.BBCEnhancer.java
public String getPropValues() throws IOException { Properties prop = new Properties(); String propFileName = "api.properties"; InputStream inputStream = getClass().getClassLoader().getResourceAsStream(propFileName); String apiKey = ""; if (inputStream != null) { prop.load(inputStream);/* w w w . ja v a2 s . c om*/ apiKey = prop.getProperty("API_KEY"); } else { throw new FileNotFoundException(); } inputStream.close(); return apiKey; }