Java Code Examples for org.eclipse.core.filesystem.IFileStore#openOutputStream()
The following examples show how to use
org.eclipse.core.filesystem.IFileStore#openOutputStream() .
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 File: GitIgnoreHandlerV1.java From orion.server with Eclipse Public License 1.0 | 5 votes |
/** * Appends a single rule in the given .gitignore file store. If necessary, the .gitignore file is created. * * @param gitignoreStore * The .gitignore file store. * @param rule * The entry to be appended to the .gitignore. * @throws CoreException * @throws IOException */ private void appendGitignore(IFileStore gitignoreStore, String rule) throws CoreException, IOException { OutputStream out = null; try { out = gitignoreStore.openOutputStream(EFS.APPEND, null); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out)); bw.write(System.getProperty("line.separator") + "/" + rule); bw.flush(); } finally { if (out != null) out.close(); } }
Example 2
Source File: AdvancedFilesTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
@Test public void testETagPutNotMatch() throws JSONException, IOException, SAXException, CoreException { String fileName = "testfile.txt"; //setup: create a file WebRequest request = getPostFilesRequest("", getNewFileJSON(fileName).toString(), fileName); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode()); //obtain file metadata and ensure data is correct request = getGetFilesRequest(fileName + "?parts=meta"); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); String etag = response.getHeaderField(ProtocolConstants.KEY_ETAG); assertNotNull(etag); //change the file on disk IFileStore fileStore = EFS.getStore(makeLocalPathAbsolute(fileName)); OutputStream out = fileStore.openOutputStream(EFS.NONE, null); out.write("New Contents".getBytes()); out.close(); //now a PUT should fail request = getPutFileRequest(fileName, "something"); request.setHeaderField("If-Match", etag); try { response = webConversation.getResponse(request); } catch (IOException e) { //inexplicably HTTPUnit throws IOException on PRECON_FAILED rather than just giving us response assertTrue(e.getMessage().indexOf(Integer.toString(HttpURLConnection.HTTP_PRECON_FAILED)) > 0); } }
Example 3
Source File: BuildSettingWizardPage.java From sarl with Apache License 2.0 | 5 votes |
private static void copyFile(File source, IFileStore target, IProgressMonitor monitor) throws IOException, CoreException { try (FileInputStream is = new FileInputStream(source)) { try (OutputStream os = target.openOutputStream(EFS.NONE, monitor)) { unsecureCopyFile(is, os); } } }
Example 4
Source File: FileHandlerV1.java From orion.server with Eclipse Public License 1.0 | 4 votes |
private void handlePatchContents(HttpServletRequest request, BufferedReader requestReader, HttpServletResponse response, IFileStore file) throws IOException, CoreException, NoSuchAlgorithmException, JSONException, ServletException { JSONObject changes = OrionServlet.readJSONRequest(request); // read file to memory Reader fileReader = new InputStreamReader(file.openInputStream(EFS.NONE, null)); StringWriter oldFile = new StringWriter(); IOUtilities.pipe(fileReader, oldFile, true, false); StringBuffer oldContents = oldFile.getBuffer(); // Remove the BOM character if it exists if (oldContents.length() > 0) { char firstChar = oldContents.charAt(0); if (firstChar == '\uFEFF' || firstChar == '\uFFFE') { oldContents.replace(0, 1, ""); } } JSONArray changeList = changes.getJSONArray("diff"); for (int i = 0; i < changeList.length(); i++) { JSONObject change = changeList.getJSONObject(i); long start = change.getLong("start"); long end = change.getLong("end"); String text = change.getString("text"); oldContents.replace((int) start, (int) end, text); } String newContents = oldContents.toString(); boolean failed = false; if (changes.has("contents")) { String contents = changes.getString("contents"); if (!newContents.equals(contents)) { failed = true; newContents = contents; } } Writer fileWriter = new OutputStreamWriter(file.openOutputStream(EFS.NONE, null), "UTF-8"); IOUtilities.pipe(new StringReader(newContents), fileWriter, false, true); if (failed) { statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_ACCEPTABLE, "Bad File Diffs. Please paste this content in a bug report: \u00A0\u00A0 " + changes.toString(), null)); return; } // return metadata with the new Etag handleGetMetadata(request, response, file); }
Example 5
Source File: SimpleMetaStoreTests.java From orion.server with Eclipse Public License 1.0 | 4 votes |
@Test public void testArchiveInvalidMetaDataFileInOrganizationalFolder() throws CoreException { // create the MetaStore IMetaStore metaStore = OrionConfiguration.getMetaStore(); // create the user UserInfo userInfo = new UserInfo(); userInfo.setUserName(testUserLogin); userInfo.setFullName(testUserLogin); metaStore.createUser(userInfo); // create the workspace String workspaceName = SimpleMetaStore.DEFAULT_WORKSPACE_NAME; WorkspaceInfo workspaceInfo = new WorkspaceInfo(); workspaceInfo.setFullName(workspaceName); workspaceInfo.setUserId(userInfo.getUniqueId()); metaStore.createWorkspace(workspaceInfo); // create a invalid metadata file IFileStore rootLocation = OrionConfiguration.getRootLocation(); String orgFolderName = "te"; IFileStore orgFolder = rootLocation.getChild(orgFolderName); assertTrue(orgFolder.fetchInfo().exists()); assertTrue(orgFolder.fetchInfo().isDirectory()); String invalid = "delete.html"; IFileStore invalidFileInOrg = orgFolder.getChild(invalid); try { OutputStream outputStream = invalidFileInOrg.openOutputStream(EFS.NONE, null); outputStream.write("<!doctype html>".getBytes()); outputStream.close(); } catch (IOException e) { fail("Count not create a test file in the Orion Project:" + e.getLocalizedMessage()); } assertTrue(invalidFileInOrg.fetchInfo().exists()); // read all the users which will trigger the archive List<String> users = metaStore.readAllUsers(); assertNotNull(users); // verify the invalid metadata file has moved to the archive IFileStore archiveFolder = rootLocation.getChild(SimpleMetaStoreUtil.ARCHIVE); assertTrue(archiveFolder.fetchInfo().exists()); assertTrue(archiveFolder.fetchInfo().isDirectory()); IFileStore archiveOrgFolder = archiveFolder.getChild(orgFolderName); assertTrue(archiveOrgFolder.fetchInfo().exists()); assertTrue(archiveOrgFolder.fetchInfo().isDirectory()); IFileStore archivedFile = archiveOrgFolder.getChild(invalid); assertTrue(archivedFile.fetchInfo().exists()); assertFalse(invalidFileInOrg.fetchInfo().exists()); }
Example 6
Source File: SimpleMetaStoreTests.java From orion.server with Eclipse Public License 1.0 | 4 votes |
@Test public void testArchiveInvalidMetaDataFileInServerWorkspaceRoot() throws CoreException { // create the MetaStore IMetaStore metaStore = OrionConfiguration.getMetaStore(); // create the user UserInfo userInfo = new UserInfo(); userInfo.setUserName(testUserLogin); userInfo.setFullName(testUserLogin); metaStore.createUser(userInfo); // create the workspace String workspaceName = SimpleMetaStore.DEFAULT_WORKSPACE_NAME; WorkspaceInfo workspaceInfo = new WorkspaceInfo(); workspaceInfo.setFullName(workspaceName); workspaceInfo.setUserId(userInfo.getUniqueId()); metaStore.createWorkspace(workspaceInfo); // create a invalid metadata file IFileStore rootLocation = OrionConfiguration.getRootLocation(); String invalid = "delete.html"; IFileStore invalidFileAtRoot = rootLocation.getChild(invalid); try { OutputStream outputStream = invalidFileAtRoot.openOutputStream(EFS.NONE, null); outputStream.write("<!doctype html>".getBytes()); outputStream.close(); } catch (IOException e) { fail("Count not create a test file in the Orion Project:" + e.getLocalizedMessage()); } assertTrue(invalidFileAtRoot.fetchInfo().exists()); // read all the users which will trigger the archive List<String> users = metaStore.readAllUsers(); assertNotNull(users); // verify the invalid metadata file has moved to the archive IFileStore archiveFolder = rootLocation.getChild(SimpleMetaStoreUtil.ARCHIVE); assertTrue(archiveFolder.fetchInfo().exists()); assertTrue(archiveFolder.fetchInfo().isDirectory()); IFileStore archivedFile = archiveFolder.getChild(invalid); assertTrue(archivedFile.fetchInfo().exists()); assertFalse(invalidFileAtRoot.fetchInfo().exists()); }
Example 7
Source File: SimpleMetaStoreTests.java From orion.server with Eclipse Public License 1.0 | 4 votes |
@Test public void testMoveProjectLinked() throws CoreException { // create the MetaStore IMetaStore metaStore = OrionConfiguration.getMetaStore(); // create the user UserInfo userInfo = new UserInfo(); userInfo.setUserName(testUserLogin); userInfo.setFullName(testUserLogin); metaStore.createUser(userInfo); // create the workspace String workspaceName = SimpleMetaStore.DEFAULT_WORKSPACE_NAME; WorkspaceInfo workspaceInfo = new WorkspaceInfo(); workspaceInfo.setFullName(workspaceName); workspaceInfo.setUserId(userInfo.getUniqueId()); metaStore.createWorkspace(workspaceInfo); // create the project String projectName = "Orion Project"; ProjectInfo projectInfo = new ProjectInfo(); projectInfo.setFullName(projectName); projectInfo.setWorkspaceId(workspaceInfo.getUniqueId()); IFileStore linkedFolder = metaStore.getUserHome(userInfo.getUniqueId()).getChild("Linked Project"); projectInfo.setContentLocation(linkedFolder.toURI()); metaStore.createProject(projectInfo); // create a project directory and file IFileStore projectFolder = projectInfo.getProjectStore(); if (!projectFolder.fetchInfo().exists()) { projectFolder.mkdir(EFS.NONE, null); } assertTrue(projectFolder.fetchInfo().exists() && projectFolder.fetchInfo().isDirectory()); String fileName = "file.html"; IFileStore file = projectFolder.getChild(fileName); try { OutputStream outputStream = file.openOutputStream(EFS.NONE, null); outputStream.write("<!doctype html>".getBytes()); outputStream.close(); } catch (IOException e) { fail("Count not create a test file in the Orion Project:" + e.getLocalizedMessage()); } assertTrue("the file in the project folder should exist.", file.fetchInfo().exists()); // move the project by renaming the project by changing the projectName String movedProjectName = "Moved Orion Project"; projectInfo.setFullName(movedProjectName); // update the project metaStore.updateProject(projectInfo); // read the project back again ProjectInfo readProjectInfo = metaStore.readProject(workspaceInfo.getUniqueId(), projectInfo.getFullName()); assertNotNull(readProjectInfo); assertTrue(readProjectInfo.getFullName().equals(movedProjectName)); // linked folder hasn't moved projectFolder = readProjectInfo.getProjectStore(); assertTrue("the linked project folder should stay the same", projectFolder.equals(linkedFolder)); assertTrue("the linked project folder should exist.", projectFolder.fetchInfo().exists()); file = projectFolder.getChild(fileName); assertTrue("the file in the linked project folder should exist.", file.fetchInfo().exists()); // delete the project contents file.delete(EFS.NONE, null); assertFalse("the file in the project folder should not exist.", file.fetchInfo().exists()); // delete the linked project projectFolder.delete(EFS.NONE, null); assertFalse("the linked project should not exist.", projectFolder.fetchInfo().exists()); }
Example 8
Source File: SimpleMetaStoreTests.java From orion.server with Eclipse Public License 1.0 | 4 votes |
@Test public void testMoveSimpleProject() throws CoreException { // create the MetaStore IMetaStore metaStore = OrionConfiguration.getMetaStore(); // create the user UserInfo userInfo = new UserInfo(); userInfo.setUserName(testUserLogin); userInfo.setFullName(testUserLogin); metaStore.createUser(userInfo); // create the workspace String workspaceName = SimpleMetaStore.DEFAULT_WORKSPACE_NAME; WorkspaceInfo workspaceInfo = new WorkspaceInfo(); workspaceInfo.setFullName(workspaceName); workspaceInfo.setUserId(userInfo.getUniqueId()); metaStore.createWorkspace(workspaceInfo); // create the project String projectName = "Orion Project"; ProjectInfo projectInfo = new ProjectInfo(); projectInfo.setFullName(projectName); projectInfo.setWorkspaceId(workspaceInfo.getUniqueId()); metaStore.createProject(projectInfo); // create a project directory and file IFileStore projectFolder = metaStore.getDefaultContentLocation(projectInfo); if (!projectFolder.fetchInfo().exists()) { projectFolder.mkdir(EFS.NONE, null); } assertTrue(projectFolder.fetchInfo().exists()); assertTrue(projectFolder.fetchInfo().isDirectory()); String fileName = "file.html"; IFileStore file = projectFolder.getChild(fileName); try { OutputStream outputStream = file.openOutputStream(EFS.NONE, null); outputStream.write("<!doctype html>".getBytes()); outputStream.close(); } catch (IOException e) { fail("Count not create a test file in the Orion Project:" + e.getLocalizedMessage()); } assertTrue("the file in the project folder should exist.", file.fetchInfo().exists()); // update the project with the content location projectInfo.setContentLocation(projectFolder.toLocalFile(EFS.NONE, null).toURI()); metaStore.updateProject(projectInfo); // move the project by renaming the project by changing the projectName String movedProjectName = "Moved Orion Project"; projectInfo.setFullName(movedProjectName); // update the project metaStore.updateProject(projectInfo); // read the project back again ProjectInfo readProjectInfo = metaStore.readProject(workspaceInfo.getUniqueId(), projectInfo.getFullName()); assertNotNull(readProjectInfo); assertTrue(readProjectInfo.getFullName().equals(movedProjectName)); // verify the local project has moved IFileStore workspaceFolder = metaStore.getWorkspaceContentLocation(workspaceInfo.getUniqueId()); projectFolder = workspaceFolder.getChild(projectName); assertFalse("the original project folder should not exist.", projectFolder.fetchInfo().exists()); projectFolder = workspaceFolder.getChild(movedProjectName); assertTrue("the new project folder should exist.", projectFolder.fetchInfo().exists() && projectFolder.fetchInfo().isDirectory()); file = projectFolder.getChild(fileName); assertTrue("the file in the project folder should exist.", file.fetchInfo().exists()); assertEquals("The ContentLocation should have been updated.", projectFolder.toLocalFile(EFS.NONE, null).toURI(), projectInfo.getContentLocation()); // delete the project contents file.delete(EFS.NONE, null); assertFalse("the file in the project folder should not exist.", file.fetchInfo().exists()); }
Example 9
Source File: NewJavaProjectWizardPageTwo.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private void copyFile(File source, IFileStore target, IProgressMonitor monitor) throws IOException, CoreException { FileInputStream is= new FileInputStream(source); OutputStream os= target.openOutputStream(EFS.NONE, monitor); copyFile(is, os); }